Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions lib/Sema/CSApply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1047,8 +1047,7 @@ namespace {
// "T.init(...)" -- pretend it has two argument lists like
// a real '.' call.
if (isa<ConstructorDecl>(member) &&
isa<CallExpr>(prev) &&
isa<TypeExpr>(cast<CallExpr>(prev)->getFn())) {
isa<CallExpr>(prev)) {
assert(maxArgCount == 2);
return 2;
}
Expand Down
6 changes: 5 additions & 1 deletion lib/Sema/PreCheckTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1925,7 +1925,7 @@ TypeExpr *PreCheckTarget::simplifyNestedTypeExpr(UnresolvedDotExpr *UDE) {
// CSGen will diagnose cases that appear outside of pack expansion
// expressions.
options |= TypeResolutionFlags::AllowPackReferences;
const auto BaseTy = TypeResolution::resolveContextualType(
auto BaseTy = TypeResolution::resolveContextualType(
InnerTypeRepr, DC, options,
[](auto unboundTy) {
// FIXME: Don't let unbound generic types escape type resolution.
Expand All @@ -1938,6 +1938,10 @@ TypeExpr *PreCheckTarget::simplifyNestedTypeExpr(UnresolvedDotExpr *UDE) {
// TypeExpr pack elements are opened in CSGen.
/*packElementOpener*/ nullptr);

// Unwrap DynamicSelfType, because Self.Foo is the same as MyClass.Foo.
if (auto *SelfTy = BaseTy->getAs<DynamicSelfType>())
BaseTy = SelfTy->getSelfType();

if (BaseTy->mayHaveMembers()) {
// See if there is a member type with this name.
auto Result = TypeChecker::lookupMemberType(DC, BaseTy, Name,
Expand Down
18 changes: 18 additions & 0 deletions test/Index/expressions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,21 @@ func castExpr(x: Any) {
// CHECK: [[@LINE+1]]:15 | struct/Swift | S1 | [[S1_USR]] | Ref
_ = x as? S1
}

// Test that initializers are indexed when called through Self.NestedType

// CHECK: [[@LINE+1]]:7 | class(internal)/Swift | Container | [[Container_USR:.*]] | Def
class Container {
// CHECK: [[@LINE+1]]:11 | class(internal)/Swift | NestedType | [[NestedType_USR:.*]] | Def
class NestedType {
// CHECK: [[@LINE+1]]:9 | constructor(internal)/Swift | init(value:) | [[NestedType_init_USR:.*]] | Def
init(value: Int) {}
}

func someFunc() {
// CHECK: [[@LINE+3]]:13 | class/Swift | Container | [[Container_USR]] | Ref
// CHECK: [[@LINE+2]]:18 | class/Swift | NestedType | [[NestedType_USR]] | Ref
// CHECK: [[@LINE+1]]:18 | constructor/Swift | init(value:) | [[NestedType_init_USR]] | Ref,Call
_ = Self.NestedType(value: 1)
}
}
58 changes: 58 additions & 0 deletions test/SILGen/bogus_curry_thunk.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// RUN: %target-swift-emit-silgen %s | %FileCheck %s

class Container {
class NestedType {}

func someFunc1() {
// This constructor call should not require a curry thunk.
_ = Container.NestedType()
}

func someFunc2() {
// This constructor call should not require a curry thunk.
_ = Self.NestedType()
}

func someFunc3() {
let m = Container.self

// This constructor call should not require a curry thunk.
_ = m.NestedType()
}
}

// CHECK-LABEL: sil hidden [ossa] @$s17bogus_curry_thunk9ContainerC9someFunc1yyF : $@convention(method) (@guaranteed Container) -> () {
// CHECK: bb0(%0 : @guaranteed $Container):
// CHECK: [[META2:%.*]] = metatype $@thick Container.NestedType.Type
// CHECK: [[FN:%.*]] = function_ref @$s17bogus_curry_thunk9ContainerC10NestedTypeCAEycfC : $@convention(method) (@thick Container.NestedType.Type) -> @owned Container.NestedType
// CHECK: [[RESULT:%.*]] = apply [[FN]]([[META2]]) : $@convention(method) (@thick Container.NestedType.Type) -> @owned Container.NestedType
// CHECK: ignored_use [[RESULT]]
// CHECK: destroy_value [[RESULT]]
// CHECK: [[TUPLE:%.*]] = tuple ()
// CHECK: return [[TUPLE]]
// CHECK: }


// CHECK-LABEL: sil hidden [ossa] @$s17bogus_curry_thunk9ContainerC9someFunc2yyF : $@convention(method) (@guaranteed Container) -> () {
// CHECK: bb0(%0 : @guaranteed $Container):
// CHECK: [[META2:%.*]] = metatype $@thick Container.NestedType.Type
// CHECK: [[FN:%.*]] = function_ref @$s17bogus_curry_thunk9ContainerC10NestedTypeCAEycfC : $@convention(method) (@thick Container.NestedType.Type) -> @owned Container.NestedType
// CHECK: [[RESULT:%.*]] = apply [[FN]]([[META2]]) : $@convention(method) (@thick Container.NestedType.Type) -> @owned Container.NestedType
// CHECK: ignored_use [[RESULT]]
// CHECK: destroy_value [[RESULT]]
// CHECK: [[TUPLE:%.*]] = tuple ()
// CHECK: return [[TUPLE]]
// CHECK: }


// CHECK-LABEL: sil hidden [ossa] @$s17bogus_curry_thunk9ContainerC9someFunc3yyF : $@convention(method) (@guaranteed Container) -> () {
// CHECK: bb0(%0 : @guaranteed $Container):
// CHECK: [[META:%.*]] = metatype $@thick Container.Type
// CHECK: [[META2:%.*]] = metatype $@thick Container.NestedType.Type
// CHECK: [[FN:%.*]] = function_ref @$s17bogus_curry_thunk9ContainerC10NestedTypeCAEycfC : $@convention(method) (@thick Container.NestedType.Type) -> @owned Container.NestedType
// CHECK: [[RESULT:%.*]] = apply [[FN]]([[META2]]) : $@convention(method) (@thick Container.NestedType.Type) -> @owned Container.NestedType
// CHECK: ignored_use [[RESULT]]
// CHECK: destroy_value [[RESULT]]
// CHECK: [[TUPLE:%.*]] = tuple ()
// CHECK: return [[TUPLE]]
// CHECK: }
13 changes: 13 additions & 0 deletions test/type/self.swift
Original file line number Diff line number Diff line change
Expand Up @@ -380,4 +380,17 @@ struct NonGeneric {
protocol P {
func foo() -> Self<Int>
// expected-error@-1 {{cannot specialize non-generic type 'Self'}}
}

// https://github.com/peripheryapp/periphery/issues/676

class Container {
class NestedType {
init(value: Int) {}
}

func someFunc() {
let _ = [Container.NestedType]() // ok
let _ = [Self.NestedType]() // ok
}
}