Swift框架在lldb中返回“模糊使用"方法扩展 [英] Swift Framework returns 'ambiguous use of' method extension in lldb

查看:78
本文介绍了Swift框架在lldb中返回“模糊使用"方法扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已升级到Xcode 11&迅速5,并在通过框架提供方法扩展时遇到了一个问题.更具体地说,在一个结构如下的项目中:

I've upgraded to Xcode 11 & swift 5, and hit an an issue with method extensions when they are made available through a framework. More specifically, in a project structured like this:

-> Main Project
-> Framework created from sources in 'Main Project'
-> Subproject using the above Framework (Sources packaged in the framework are not visible to the sub-project)

所有内容都能编译并正常运行,但是在子项目上运行调试会话时,从lldb命令行调用时,框架"中的所有扩展都返回error: ambiguous use of.这是一个给出想法的代码示例:

Everything compiles and runs fine, but when running debug sessions on the subproject, all extensions in 'Framework' return error: ambiguous use of when invoked from the lldb command line. Here is a code sample to give an idea:

创建一个macOs命令行项目,并在文件Spells.swift中添加新目标"MagicFramework"(确保该文件对Main& MagicFramework可见)

Create a macOs command line project, and add a new target, 'MagicFramework', and in a file Spells.swift (make sure the file is visible to Main & MagicFramework)

import Foundation

extension String {
    public func castSpell() -> String {
        return "✨ " + self
    }
}

然后在文件wizard.swift(仅对Wizard可见)中创建一个子项目"Wizard":

Then create a subproject 'Wizard', and in a file wizard.swift (visible to Wizard only):

import Foundation
import MagicFramework


public class Tadaa {

    public func magic(spell:String) -> String {
        return spell.castSpell()
    }
}

在Wizard的main.swift文件中,添加:

in Wizard's main.swift file, add:

import Foundation

let aa = Tadaa().magic(spell: "this is magic")

print(aa)

您应具有以下结构:

-> Main project
----> MagicFramework
----> Wizard subproject

然后构建并运行'Wizard'子程序,在Tadaa中的spell.castSpell()上有一个断点.在lldb提示符下,键入:

then build&run 'Wizard' sub, with a break point on spell.castSpell() in Tadaa. At the lldb prompt, type:

(lldb)po spell.castSpell()
error: <EXPR>:3:1: error: ambiguous use of 'castSpell()'
spell.castSpell()

为什么? Xcode 10不会发生此问题.

why?? This problem didn't occur with Xcode 10.

推荐答案

以我的拙见,这只能是一个错误.

In my humble opinion, this can only be a bug.

如果我设置了您要回答的问题的示例,则可以重现该问题.

If I set up the example you are giving in your question, I can reproduce the problem.

在断点上,我得到

(lldb) po spell.castSpell()
error: <EXPR>:3:1: error: ambiguous use of 'castSpell()'
spell.castSpell()
^

正如您所描述的.

但是,如果我在lldb中查找函数castSpell,则会得到:

However, if I look up the function castSpell in lldb, I get:

(lldb) image lookup -vn castSpell
1 match found in /Users/lameyl01/Library/Developer/Xcode/DerivedData/Main-dsjbnoyousgzmrdnqxtxoeyeyzpv/Build/Products/Debug/MagicFramework.framework/Versions/A/MagicFramework:
        Address: MagicFramework[0x0000000000000ab0] (MagicFramework.__TEXT.__text + 0)
        Summary: MagicFramework`(extension in MagicFramework):Swift.String.castSpell() -> Swift.String at Spells.swift:12
         Module: file = "/Users/lameyl01/Library/Developer/Xcode/DerivedData/Main-dsjbnoyousgzmrdnqxtxoeyeyzpv/Build/Products/Debug/MagicFramework.framework/Versions/A/MagicFramework", arch = "x86_64"
    CompileUnit: id = {0x00000000}, file = "/Users/lameyl01/tmp/Main/MagicFramework/Spells.swift", language = "swift"
       Function: id = {0x100000038}, name = "(extension in MagicFramework):Swift.String.castSpell() -> Swift.String", mangled = "$sSS14MagicFrameworkE9castSpellSSyF", range = [0x000000010033fab0-0x000000010033fb21)
       FuncType: id = {0x100000038}, byte-size = 8, decl = Spells.swift:12, compiler_type = "() -> ()"
         Blocks: id = {0x100000038}, range = [0x10033fab0-0x10033fb21)
      LineEntry: [0x000000010033fab0-0x000000010033fabf): /Users/lameyl01/tmp/Main/MagicFramework/Spells.swift:12
         Symbol: id = {0x00000005}, range = [0x000000010033fab0-0x000000010033fb21), name="(extension in MagicFramework):Swift.String.castSpell() -> Swift.String", mangled="$sSS14MagicFrameworkE9castSpellSSyF"
       Variable: id = {0x100000055}, name = "self", type = "Swift.String", location = DW_OP_fbreg(-16), decl = Spells.swift:12

所以这意味着lldb找到了一个完全匹配的内容:MagicFramework库中的扩展名.因此,没有理由为什么这应该是模棱两可的.

So that means that lldb has found exactly one match: The extension in the MagicFramework library. So there is no reason why this should be ambiguous.

为了完整起见,我还检查了llbd看到的变量spell的类型:

For the sake of completeness I also checked the type of the variable spell as llbd sees it:

(lldb) frame variable spell
(String) spell = "this is magic"

所以总结一下: lldb 知道类型为字符串.它知道,在扩展名中定义了一个函数castSpell,并且它确切地知道了该函数的一个实现.但它仍然显示错误消息.

So to summarize: lldb knows the type is String. It knows that there is a function castSpell defined in the extension and it knows of exactly one implementation of said function. But still it shows the error message.

因此,除非我在这里缺少必要的内容,否则这一定是lldb错误.

So unless I'm missing something essential here, this must be a lldb bug.

这篇关于Swift框架在lldb中返回“模糊使用"方法扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆