diff --git a/lib/AST/GenericSignatureBuilder.cpp b/lib/AST/GenericSignatureBuilder.cpp index d86f39265b74e..e083e77f7bd03 100644 --- a/lib/AST/GenericSignatureBuilder.cpp +++ b/lib/AST/GenericSignatureBuilder.cpp @@ -837,6 +837,11 @@ const RequirementSource *RequirementSource::getMinimalConformanceSource( if (parentEquivClass->concreteType) derivedViaConcrete = true; + else if (parentEquivClass->superclass && + builder.lookupConformance(parentType->getCanonicalType(), + parentEquivClass->superclass, + source->getProtocolDecl())) + derivedViaConcrete = true; // The parent potential archetype must conform to the protocol in which // this requirement resides. Add this constraint. diff --git a/lib/Sema/CSApply.cpp b/lib/Sema/CSApply.cpp index 40b890734fa18..19b2d22f0ff5a 100644 --- a/lib/Sema/CSApply.cpp +++ b/lib/Sema/CSApply.cpp @@ -2643,6 +2643,7 @@ namespace { if (!witness || !isa(witness.getDecl())) return nullptr; expr->setInitializer(witness); + expr->setArg(cs.coerceToRValue(expr->getArg())); return expr; } diff --git a/lib/Sema/CSBindings.cpp b/lib/Sema/CSBindings.cpp index 8cb067e112841..b4ac022c4811d 100644 --- a/lib/Sema/CSBindings.cpp +++ b/lib/Sema/CSBindings.cpp @@ -69,6 +69,9 @@ void ConstraintSystem::inferTransitiveSupertypeBindings( auto type = binding.BindingType; + if (type->isHole()) + continue; + if (!existingTypes.insert(type->getCanonicalType()).second) continue; diff --git a/test/Constraints/overload.swift b/test/Constraints/overload.swift index 9877c41ec0ab8..1361b0ce76895 100644 --- a/test/Constraints/overload.swift +++ b/test/Constraints/overload.swift @@ -238,3 +238,10 @@ func autoclosure1(_: [T], _: X) { } func test_autoclosure1(ia: [Int]) { autoclosure1(ia, X()) // okay: resolves to the second function } + +// rdar://problem/64368545 - failed to produce diagnostic (hole propagated to func result without recording a fix) +func test_no_hole_propagation() { + func test(withArguments arguments: [String]) -> String { + return arguments.reduce(0, +) // expected-error {{cannot convert value of type 'Int' to expected argument type 'String'}} + } +} diff --git a/test/Generics/superclass_constraint_self_derived.swift b/test/Generics/superclass_constraint_self_derived.swift new file mode 100644 index 0000000000000..074fc3c22f7ae --- /dev/null +++ b/test/Generics/superclass_constraint_self_derived.swift @@ -0,0 +1,25 @@ +// RUN: %target-typecheck-verify-swift + +protocol P { + associatedtype T : Q +} + +protocol Q { + associatedtype T : R + + var t: T { get } +} + +protocol R {} + +func takesR(_: T) {} + +class C : P {} + +struct Outer { + struct Inner where T : C { + func doStuff(_ u: U) { + takesR(u.t) + } + } +} diff --git a/test/SILGen/class_conforms_with_default_implementation.swift b/test/SILGen/class_conforms_with_default_implementation.swift new file mode 100644 index 0000000000000..e07ee24889dde --- /dev/null +++ b/test/SILGen/class_conforms_with_default_implementation.swift @@ -0,0 +1,48 @@ +// RUN: %target-swift-emit-silgen %s | %FileCheck %s + +protocol P { + associatedtype T : Q + func foo() +} + +extension P { + func foo() {} +} + +protocol Q {} + +class C : P {} + +protocol PP { + associatedtype T : QQ + func foo() +} + +extension PP { + func foo() {} +} + +class QQ {} + +class CC : PP {} + +// CHECK-LABEL: sil private [transparent] [thunk] [ossa] @$s42class_conforms_with_default_implementation1CCyqd__GAA1PA2aEP3fooyyFTW : $@convention(witness_method: P) <τ_0_0><τ_1_0 where τ_0_0 : C<τ_1_0>, τ_1_0 : Q> (@in_guaranteed τ_0_0) -> () { +// CHECK: [[WITNESS:%.*]] = function_ref @$s42class_conforms_with_default_implementation1PPAAE3fooyyF : $@convention(method) <τ_0_0 where τ_0_0 : P> (@in_guaranteed τ_0_0) -> () +// CHECK: apply [[WITNESS]]<τ_0_0>(%0) : $@convention(method) <τ_0_0 where τ_0_0 : P> (@in_guaranteed τ_0_0) -> () +// CHECK: return + +// CHECK-LABEL: sil private [transparent] [thunk] [ossa] @$s42class_conforms_with_default_implementation2CCCyqd__GAA2PPA2aEP3fooyyFTW : $@convention(witness_method: PP) <τ_0_0><τ_1_0 where τ_0_0 : CC<τ_1_0>, τ_1_0 : QQ> (@in_guaranteed τ_0_0) -> () { +// CHECK: [[WITNESS:%.*]] = function_ref @$s42class_conforms_with_default_implementation2PPPAAE3fooyyF : $@convention(method) <τ_0_0 where τ_0_0 : PP> (@in_guaranteed τ_0_0) -> () +// CHECK: apply [[WITNESS]]<τ_0_0>(%0) : $@convention(method) <τ_0_0 where τ_0_0 : PP> (@in_guaranteed τ_0_0) -> () +// CHECK: return + +// CHECK-LABEL: sil_witness_table hidden C: P module class_conforms_with_default_implementation { +// CHECK-NEXT: associated_type_protocol (T: Q): dependent +// CHECK-NEXT: associated_type T: T +// CHECK-NEXT: method #P.foo: (Self) -> () -> () : @$s42class_conforms_with_default_implementation1CCyqd__GAA1PA2aEP3fooyyFTW +// CHECK-NEXT: } + +// CHECK-LABEL: sil_witness_table hidden CC: PP module class_conforms_with_default_implementation { +// CHECK-NEXT: associated_type T: T +// CHECK-NEXT: method #PP.foo: (Self) -> () -> () : @$s42class_conforms_with_default_implementation2CCCyqd__GAA2PPA2aEP3fooyyFTW +// CHECK-NEXT: } diff --git a/test/Sema/object_literals_osx.swift b/test/Sema/object_literals_osx.swift index b49c28989f9bd..b49ecf4c69702 100644 --- a/test/Sema/object_literals_osx.swift +++ b/test/Sema/object_literals_osx.swift @@ -27,3 +27,13 @@ let text = #fileLiteral(resourceName: "TextFile.txt").relativeString! // expecte // rdar://problem/49861813 #fileLiteral() // expected-error{{missing argument for parameter 'resourceName' in call}} expected-error{{could not infer type of file reference literal}} expected-note{{import Foundation to use 'URL' as the default file reference literal type}} + +// rdar://problem/62927467 +func test_literal_arguments_are_loaded() { + var resource = "foo.txt" // expected-warning {{variable 'resource' was never mutated; consider changing to 'let' constant}} + let _: Path = #fileLiteral(resourceName: resource) // Ok + + func test(red: inout Float, green: inout Float) -> S { + return #colorLiteral(red: red, green: green, blue: 1, alpha: 1) // Ok + } +} diff --git a/validation-test/compiler_crashers_2/sr11108.swift b/validation-test/compiler_crashers_2_fixed/sr11108.swift similarity index 87% rename from validation-test/compiler_crashers_2/sr11108.swift rename to validation-test/compiler_crashers_2_fixed/sr11108.swift index 8c82d6cbc9c9d..14f1ec3e8b8b5 100644 --- a/validation-test/compiler_crashers_2/sr11108.swift +++ b/validation-test/compiler_crashers_2_fixed/sr11108.swift @@ -1,6 +1,4 @@ -// RUN: not --crash %target-swift-emit-silgen %s - -// REQUIRES: asserts +// RUN: %target-swift-emit-silgen %s protocol Example { associatedtype Signed: SignedInteger