Skip to content

Overloaded Foo.NestedType() does not create ConstructorRefCallExpr #65726

Open
@keith

Description

@keith

With this code:

// Module0
public struct Thing {
  public struct Nested {
    public init(string: String) {}
  }
}
// Module1
public struct Thing {}
// Module2
import Module0
import Module1

func foo() {
    _ = Thing.Nested(string: "lol")
}

The AST of Module2 does not contain a ConstructorRefCallExpr, and therefore does not correctly index the constructor being referenced. Here is the full AST:

(source_file "/Users/ksmiley/dev/oss-swift/build/Ninja-RelWithDebInfoAssert/swift-macosx-arm64/test-macosx-arm64/Index/Output/ambiguous-type.swift.tmp/file3.swift"
  (import_decl range=[/Users/ksmiley/dev/oss-swift/build/Ninja-RelWithDebInfoAssert/swift-macosx-arm64/test-macosx-arm64/Index/Output/ambiguous-type.swift.tmp/file3.swift:1:1 - line:1:8] 'file1')
  (import_decl range=[/Users/ksmiley/dev/oss-swift/build/Ninja-RelWithDebInfoAssert/swift-macosx-arm64/test-macosx-arm64/Index/Output/ambiguous-type.swift.tmp/file3.swift:2:1 - line:2:8] 'file2')
  (func_decl range=[/Users/ksmiley/dev/oss-swift/build/Ninja-RelWithDebInfoAssert/swift-macosx-arm64/test-macosx-arm64/Index/Output/ambiguous-type.swift.tmp/file3.swift:4:1 - line:6:1] "foo()" interface type='() -> ()' access=internal
    (parameter_list range=[/Users/ksmiley/dev/oss-swift/build/Ninja-RelWithDebInfoAssert/swift-macosx-arm64/test-macosx-arm64/Index/Output/ambiguous-type.swift.tmp/file3.swift:4:9 - line:4:10])
    (brace_stmt range=[/Users/ksmiley/dev/oss-swift/build/Ninja-RelWithDebInfoAssert/swift-macosx-arm64/test-macosx-arm64/Index/Output/ambiguous-type.swift.tmp/file3.swift:4:12 - line:6:1]
      (assign_expr type='()' location=/Users/ksmiley/dev/oss-swift/build/Ninja-RelWithDebInfoAssert/swift-macosx-arm64/test-macosx-arm64/Index/Output/ambiguous-type.swift.tmp/file3.swift:5:5 range=[/Users/ksmiley/dev/oss-swift/build/Ninja-RelWithDebInfoAssert/swift-macosx-arm64/test-macosx-arm64/Index/Output/ambiguous-type.swift.tmp/file3.swift:5:3 - line:5:33]
        (discard_assignment_expr type='@lvalue Thing.Nested' location=/Users/ksmiley/dev/oss-swift/build/Ninja-RelWithDebInfoAssert/swift-macosx-arm64/test-macosx-arm64/Index/Output/ambiguous-type.swift.tmp/file3.swift:5:3 range=[/Users/ksmiley/dev/oss-swift/build/Ninja-RelWithDebInfoAssert/swift-macosx-arm64/test-macosx-arm64/Index/Output/ambiguous-type.swift.tmp/file3.swift:5:3 - line:5:3])
        (call_expr type='Thing.Nested' location=/Users/ksmiley/dev/oss-swift/build/Ninja-RelWithDebInfoAssert/swift-macosx-arm64/test-macosx-arm64/Index/Output/ambiguous-type.swift.tmp/file3.swift:5:7 range=[/Users/ksmiley/dev/oss-swift/build/Ninja-RelWithDebInfoAssert/swift-macosx-arm64/test-macosx-arm64/Index/Output/ambiguous-type.swift.tmp/file3.swift:5:7 - line:5:33] nothrow
          (autoclosure_expr type='(String) -> Thing.Nested' location=/Users/ksmiley/dev/oss-swift/build/Ninja-RelWithDebInfoAssert/swift-macosx-arm64/test-macosx-arm64/Index/Output/ambiguous-type.swift.tmp/file3.swift:5:7 range=[/Users/ksmiley/dev/oss-swift/build/Ninja-RelWithDebInfoAssert/swift-macosx-arm64/test-macosx-arm64/Index/Output/ambiguous-type.swift.tmp/file3.swift:5:7 - line:5:13] discriminator=0 escaping

            (parameter_list
              (parameter "string" apiName=string type='String' interface type='String'))
            (call_expr implicit type='Thing.Nested' location=/Users/ksmiley/dev/oss-swift/build/Ninja-RelWithDebInfoAssert/swift-macosx-arm64/test-macosx-arm64/Index/Output/ambiguous-type.swift.tmp/file3.swift:5:7 range=[/Users/ksmiley/dev/oss-swift/build/Ninja-RelWithDebInfoAssert/swift-macosx-arm64/test-macosx-arm64/Index/Output/ambiguous-type.swift.tmp/file3.swift:5:7 - line:5:13] nothrow
              (dot_syntax_call_expr implicit type='(String) -> Thing.Nested' location=/Users/ksmiley/dev/oss-swift/build/Ninja-RelWithDebInfoAssert/swift-macosx-arm64/test-macosx-arm64/Index/Output/ambiguous-type.swift.tmp/file3.swift:5:7 range=[/Users/ksmiley/dev/oss-swift/build/Ninja-RelWithDebInfoAssert/swift-macosx-arm64/test-macosx-arm64/Index/Output/ambiguous-type.swift.tmp/file3.swift:5:7 - line:5:13] nothrow
                (declref_expr implicit type='(Thing.Nested.Type) -> (String) -> Thing.Nested' location=/Users/ksmiley/dev/oss-swift/build/Ninja-RelWithDebInfoAssert/swift-macosx-arm64/test-macosx-arm64/Index/Output/ambiguous-type.swift.tmp/file3.swift:5:13 range=[/Users/ksmiley/dev/oss-swift/build/Ninja-RelWithDebInfoAssert/swift-macosx-arm64/test-macosx-arm64/Index/Output/ambiguous-type.swift.tmp/file3.swift:5:13 - line:5:13] decl=file1.(file).Thing.Nested.init(string:) function_ref=single)
                (argument_list implicit
                  (argument
                    (dot_self_expr type='Thing.Nested.Type' location=/Users/ksmiley/dev/oss-swift/build/Ninja-RelWithDebInfoAssert/swift-macosx-arm64/test-macosx-arm64/Index/Output/ambiguous-type.swift.tmp/file3.swift:5:7 range=[/Users/ksmiley/dev/oss-swift/build/Ninja-RelWithDebInfoAssert/swift-macosx-arm64/test-macosx-arm64/Index/Output/ambiguous-type.swift.tmp/file3.swift:5:7 - line:5:13]
                      (dot_syntax_base_ignored type='Thing.Nested.Type' location=/Users/ksmiley/dev/oss-swift/build/Ninja-RelWithDebInfoAssert/swift-macosx-arm64/test-macosx-arm64/Index/Output/ambiguous-type.swift.tmp/file3.swift:5:7 range=[/Users/ksmiley/dev/oss-swift/build/Ninja-RelWithDebInfoAssert/swift-macosx-arm64/test-macosx-arm64/Index/Output/ambiguous-type.swift.tmp/file3.swift:5:7 - line:5:13]
                        (type_expr type='Thing.Type' location=/Users/ksmiley/dev/oss-swift/build/Ninja-RelWithDebInfoAssert/swift-macosx-arm64/test-macosx-arm64/Index/Output/ambiguous-type.swift.tmp/file3.swift:5:7 range=[/Users/ksmiley/dev/oss-swift/build/Ninja-RelWithDebInfoAssert/swift-macosx-arm64/test-macosx-arm64/Index/Output/ambiguous-type.swift.tmp/file3.swift:5:7 - line:5:7] typerepr='Thing')
                        (type_expr type='Thing.Nested.Type' location=/Users/ksmiley/dev/oss-swift/build/Ninja-RelWithDebInfoAssert/swift-macosx-arm64/test-macosx-arm64/Index/Output/ambiguous-type.swift.tmp/file3.swift:5:13 range=[/Users/ksmiley/dev/oss-swift/build/Ninja-RelWithDebInfoAssert/swift-macosx-arm64/test-macosx-arm64/Index/Output/ambiguous-type.swift.tmp/file3.swift:5:13 - line:5:13] typerepr='Nested'))))))
              (argument_list implicit labels=string:
                (argument label=string
                  (declref_expr implicit type='String' decl=file3.(file).foo().autoclosure discriminator=0.string function_ref=unapplied)))))
          (argument_list labels=string:
            (argument label=string
              (string_literal_expr type='String' location=/Users/ksmiley/dev/oss-swift/build/Ninja-RelWithDebInfoAssert/swift-macosx-arm64/test-macosx-arm64/Index/Output/ambiguous-type.swift.tmp/file3.swift:5:28 range=[/Users/ksmiley/dev/oss-swift/build/Ninja-RelWithDebInfoAssert/swift-macosx-arm64/test-macosx-arm64/Index/Output/ambiguous-type.swift.tmp/file3.swift:5:28 - line:5:28] encoding=utf8 value="lol" builtin_initializer=Swift.(file).String extension.init(_builtinStringLiteral:utf8CodeUnitCount:isASCII:) initializer=**NULL**))))))))

If you remove the import to Module1, it resolves the issue.

ed3555a

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.call expressionsFeature → expressions: Call expressionsdeclarationsFeature: declarationsexpressionsFeature: expressionsindexingArea → source tooling: AST indexinginitFeature → declarations: Initializersmultiple modulesFlag: An issue whose reproduction requires multiple modulesnested typesFeature: nested typesoverloadingFeature: Overloading symbol namessource toolingArea: IDE support, SourceKit, and other source toolingswift 5.9type declarationsFeature → declarations: Type declarationstypesFeature: typesunexpected behaviorBug: Unexpected behavior or incorrect output

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions