mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[CS] Sink placeholder handling logic into Solution::simplifyType
Move the logic from `FailureDiagnostic::resolveType` into `Solution::simplifyType` to allow completion to use it too. While here, also handle cases where the placeholder is from a different member of the equivalence class to the generic parameter.
This commit is contained in:
@@ -96,37 +96,7 @@ Type FailureDiagnostic::getRawType(ASTNode node) const {
|
||||
|
||||
Type FailureDiagnostic::resolveType(Type rawType, bool reconstituteSugar,
|
||||
bool wantRValue) const {
|
||||
rawType = rawType.transformRec([&](Type type) -> std::optional<Type> {
|
||||
if (auto *typeVar = type->getAs<TypeVariableType>()) {
|
||||
auto resolvedType = S.simplifyType(typeVar);
|
||||
|
||||
if (!resolvedType->hasError())
|
||||
return resolvedType;
|
||||
|
||||
// If type variable was simplified to an unresolved pack expansion
|
||||
// type, let's examine its original pattern type because it could
|
||||
// contain type variables replaceable with their generic parameter
|
||||
// types.
|
||||
if (auto *expansion = resolvedType->getAs<PackExpansionType>()) {
|
||||
auto *locator = typeVar->getImpl().getLocator();
|
||||
auto *openedExpansionTy =
|
||||
locator->castLastElementTo<LocatorPathElt::PackExpansionType>()
|
||||
.getOpenedType();
|
||||
auto patternType = resolveType(openedExpansionTy->getPatternType());
|
||||
return PackExpansionType::get(patternType, expansion->getCountType());
|
||||
}
|
||||
|
||||
Type GP = typeVar->getImpl().getGenericParameter();
|
||||
return resolvedType->is<ErrorType>() && GP
|
||||
? ErrorType::get(GP)
|
||||
: resolvedType;
|
||||
}
|
||||
|
||||
if (type->isPlaceholder())
|
||||
return ErrorType::get(type->getASTContext());
|
||||
|
||||
return std::nullopt;
|
||||
});
|
||||
rawType = S.simplifyType(rawType);
|
||||
|
||||
if (rawType->hasElementArchetype()) {
|
||||
auto *env = getDC()->getGenericEnvironmentOfContext();
|
||||
|
||||
@@ -1861,6 +1861,71 @@ void Solution::recordSingleArgMatchingChoice(ConstraintLocator *locator) {
|
||||
MatchCallArgumentResult::forArity(1)});
|
||||
}
|
||||
|
||||
static GenericTypeParamType *
|
||||
getGenericParamForHoleTypeVar(TypeVariableType *tv, const Solution &S) {
|
||||
auto getGenericParam = [](TypeVariableType *tv) -> GenericTypeParamType * {
|
||||
auto *gp = tv->getImpl().getGenericParameter();
|
||||
if (!gp)
|
||||
return nullptr;
|
||||
// Note we only consider generic parameters with underlying decls since for
|
||||
// diagnostics we want something we can print, and for completion we want
|
||||
// something we can extract a GenericEnvironment to produce an archetype.
|
||||
return gp->getDecl() ? gp : nullptr;
|
||||
};
|
||||
|
||||
if (auto *gp = getGenericParam(tv))
|
||||
return gp;
|
||||
|
||||
// Sometimes we run into cases where the originator of a hole isn't for
|
||||
// the generic parameter, instead it's for a member of its equivalence
|
||||
// class. Handle this by looking through all the bindings to see if we have
|
||||
// the same hole bound to a generic parameter type variable.
|
||||
for (auto &binding : S.typeBindings) {
|
||||
if (auto *hole = binding.second->getAs<PlaceholderType>()) {
|
||||
if (hole->getOriginator().dyn_cast<TypeVariableType *>() == tv) {
|
||||
if (auto *gp = getGenericParam(binding.first))
|
||||
return gp;
|
||||
}
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static Type replacePlaceholderType(PlaceholderType *placeholder,
|
||||
const Solution &S) {
|
||||
auto &ctx = S.getConstraintSystem().getASTContext();
|
||||
auto origTy = [&]() -> Type {
|
||||
auto orig = placeholder->getOriginator();
|
||||
if (auto *tv = orig.dyn_cast<TypeVariableType *>())
|
||||
return tv;
|
||||
if (auto *dmt = orig.dyn_cast<DependentMemberType *>())
|
||||
return dmt;
|
||||
return Type();
|
||||
}();
|
||||
if (!origTy)
|
||||
return ErrorType::get(ctx);
|
||||
|
||||
// Try replace the type variable with its original generic parameter type.
|
||||
auto replacement = origTy.transformRec([&](Type ty) -> std::optional<Type> {
|
||||
auto *tv = dyn_cast<TypeVariableType>(ty.getPointer());
|
||||
if (!tv)
|
||||
return std::nullopt;
|
||||
|
||||
auto *gp = getGenericParamForHoleTypeVar(tv, S);
|
||||
if (!gp)
|
||||
return std::nullopt;
|
||||
|
||||
return Type(gp);
|
||||
});
|
||||
if (isa<TypeVariableType>(replacement.getPointer()))
|
||||
return ErrorType::get(ctx);
|
||||
|
||||
// Return an ErrorType with the replacement as the original type. Note that
|
||||
// if we failed to replace a type variable with a generic parameter in a
|
||||
// dependent member, `ErrorType::get` will fold it away.
|
||||
return ErrorType::get(replacement);
|
||||
}
|
||||
|
||||
Type Solution::simplifyType(Type type, bool wantInterfaceType) const {
|
||||
// If we've been asked for an interface type, start by mapping any archetypes
|
||||
// out of context.
|
||||
@@ -1899,7 +1964,11 @@ Type Solution::simplifyType(Type type, bool wantInterfaceType) const {
|
||||
return type;
|
||||
|
||||
auto *typePtr = type.getPointer();
|
||||
if (isa<TypeVariableType>(typePtr) || isa<PlaceholderType>(typePtr))
|
||||
|
||||
if (auto *placeholder = dyn_cast<PlaceholderType>(typePtr))
|
||||
return replacePlaceholderType(placeholder, *this);
|
||||
|
||||
if (isa<TypeVariableType>(typePtr))
|
||||
return ErrorType::get(ctx);
|
||||
|
||||
return std::nullopt;
|
||||
|
||||
@@ -19,11 +19,11 @@ func attributedInOutFunc(x: inout @convention(c) () -> Int32) {} // expected-not
|
||||
attributedInOutFunc() // expected-error {{missing argument for parameter 'x' in call}} {{21-21=x: &<#@convention(c) () -> Int32#>}}
|
||||
|
||||
func genericFunc1<T>(x: T) {} // expected-note * {{here}}
|
||||
genericFunc1() // expected-error {{missing argument for parameter 'x' in call}} {{14-14=x: <#_#>}}
|
||||
genericFunc1() // expected-error {{missing argument for parameter 'x' in call}} {{14-14=x: <#T#>}}
|
||||
|
||||
protocol P {}
|
||||
func genericFunc2<T : P>(x: T) {} // expected-note * {{here}}
|
||||
genericFunc2() // expected-error {{missing argument for parameter 'x' in call}} {{14-14=x: <#_#>}}
|
||||
genericFunc2() // expected-error {{missing argument for parameter 'x' in call}} {{14-14=x: <#T#>}}
|
||||
|
||||
typealias MyInt = Int
|
||||
func aliasedFunc(x: MyInt) {} // expected-note * {{here}}
|
||||
|
||||
@@ -1040,8 +1040,8 @@ func test_requirement_failures_in_ambiguous_context() {
|
||||
// rdar://106054263 - failed to produce a diagnostic upon generic argument mismatch
|
||||
func test_mismatches_with_dependent_member_generic_arguments() {
|
||||
struct Binding<T, U> {}
|
||||
// expected-note@-1 {{arguments to generic parameter 'T' ('Double?' and 'Data.SomeAssociated') are expected to be equal}}
|
||||
// expected-note@-2 {{arguments to generic parameter 'U' ('Int' and 'Data.SomeAssociated') are expected to be equal}}
|
||||
// expected-note@-1 {{arguments to generic parameter 'T' ('Double?' and 'Data.SomeAssociated' (aka 'String')) are expected to be equal}}
|
||||
// expected-note@-2 {{arguments to generic parameter 'U' ('Int' and 'Data.SomeAssociated' (aka 'String')) are expected to be equal}}
|
||||
|
||||
struct Data : SomeProtocol {
|
||||
typealias SomeAssociated = String
|
||||
@@ -1058,7 +1058,7 @@ func test_mismatches_with_dependent_member_generic_arguments() {
|
||||
|
||||
test2(Optional<Int>(nil), Data())
|
||||
// expected-error@-1 {{cannot convert value of type 'Optional<Int>' to expected argument type 'Optional<Data.SomeAssociated>'}}
|
||||
// expected-note@-2 {{arguments to generic parameter 'Wrapped' ('Int' and 'Data.SomeAssociated') are expected to be equal}}
|
||||
// expected-note@-2 {{arguments to generic parameter 'Wrapped' ('Int' and 'Data.SomeAssociated' (aka 'String')) are expected to be equal}}
|
||||
}
|
||||
|
||||
extension Dictionary where Value == Any { // expected-note {{where 'Value' = 'any P'}}
|
||||
|
||||
@@ -240,10 +240,10 @@ func patternInstantiationConcreteValid() {
|
||||
|
||||
func patternInstantiationConcreteInvalid() {
|
||||
let _: Set<Int> = patternInstantiationTupleTest1()
|
||||
// expected-error@-1 {{cannot convert value of type '(repeat Array<_>)' to specified type 'Set<Int>'}}
|
||||
// expected-error@-1 {{cannot convert value of type 'Array<_>' to specified type 'Set<Int>'}}
|
||||
// expected-error@-2 {{could not infer pack element #0 from context}}
|
||||
|
||||
let _: (Array<Int>, Set<String>) = patternInstantiationTupleTest1() // expected-error {{'(repeat Array<Int, _>)' is not convertible to '(Array<Int>, Set<String>)', tuples have a different number of elements}}
|
||||
let _: (Array<Int>, Set<String>) = patternInstantiationTupleTest1() // expected-error {{cannot convert value of type '(Array<Int>, Array<_>)' to specified type '(Array<Int>, Set<String>)'}}
|
||||
// expected-error@-1 {{could not infer pack element #1 from context}}
|
||||
}
|
||||
|
||||
@@ -274,7 +274,7 @@ func patternInstantiationGenericInvalid<each T: Hashable>(t: repeat each T) {
|
||||
let _: (repeat Set<each T>) = patternInstantiationTupleTest1() // expected-error {{cannot convert value of type '(repeat Array<each T>)' to specified type '(repeat Set<each T>)}}
|
||||
// expected-error@-1 {{generic parameter 'each T' could not be inferred}}
|
||||
|
||||
let _: (repeat Array<each T>, Set<String>) = patternInstantiationTupleTest1() // expected-error {{'(repeat Array<repeat each T, _>)' is not convertible to '(repeat Array<each T>, Set<String>)', tuples have a different number of elements}}
|
||||
let _: (repeat Array<each T>, Set<String>) = patternInstantiationTupleTest1() // expected-error {{cannot convert value of type '(repeat Array<each T>, Array<_>)' to specified type '(repeat Array<each T>, Set<String>)'}}
|
||||
// expected-error@-1 {{could not infer pack element #1 from context}}
|
||||
}
|
||||
|
||||
|
||||
@@ -1728,7 +1728,7 @@ do {
|
||||
do {
|
||||
func f(_: Int...) {}
|
||||
let _ = [(1, 2, 3)].map(f) // expected-error {{no exact matches in call to instance method 'map'}}
|
||||
// expected-note@-1 {{found candidate with type '(((Int, Int, Int)) -> _) -> Array<_>'}}
|
||||
// expected-note@-1 2{{found candidate with type '(((Int, Int, Int)) -> T) -> [T]'}}
|
||||
}
|
||||
|
||||
// rdar://problem/48443263 - cannot convert value of type '() -> Void' to expected argument type '(_) -> Void'
|
||||
|
||||
@@ -7,16 +7,16 @@ struct W<T> {}
|
||||
struct S<C1: Collection> {
|
||||
init(){}
|
||||
// expected-note@+2 {{where 'C1.Element' = 'W<C1>', 'main.W<C2.Element>' = 'main.W<C2.Element>'}}
|
||||
// expected-note@+1 {{where 'C1.Element' = 'W<String>', 'W<C2.Element>' = 'W<Array<Int>.Element>'}}
|
||||
// expected-note@+1 {{where 'C1.Element' = 'W<String>', 'W<C2.Element>' = 'W<Int>'}}
|
||||
init<C2>(_ c2: W<C2>) where C2: Collection, C1.Element == W<C2.Element> {}
|
||||
// expected-note@+1 {{where 'C1.Element' = 'W<String>', 'W<C2.Element>' = 'W<Array<Int>.Element>'}}
|
||||
// expected-note@+1 {{where 'C1.Element' = 'W<String>', 'W<C2.Element>' = 'W<Int>'}}
|
||||
static func f<C2>(_ c2: W<C2>) where C2: Collection, C1.Element == W<C2.Element> {}
|
||||
// expected-note@+1 {{where 'C1.Element' = 'W<String>', 'W<C2.Element>' = 'W<Array<Int>.Element>'}}
|
||||
// expected-note@+1 {{where 'C1.Element' = 'W<String>', 'W<C2.Element>' = 'W<Int>'}}
|
||||
func instancef<C2>(_ c2: W<C2>) where C2: Collection, C1.Element == W<C2.Element> {}
|
||||
}
|
||||
let _ = S<[W<String>]>(W<[Int]>()) // expected-error{{initializer 'init(_:)' requires the types 'W<String>' and 'W<Array<Int>.Element>' be equivalent}}
|
||||
let _ = S<[W<String>]>.f(W<[Int]>()) // expected-error{{static method 'f' requires the types 'W<String>' and 'W<Array<Int>.Element>' be equivalent}}
|
||||
let _ = S<[W<String>]>().instancef(W<[Int]>()) // expected-error{{instance method 'instancef' requires the types 'W<String>' and 'W<Array<Int>.Element>' be equivalent}}
|
||||
let _ = S<[W<String>]>(W<[Int]>()) // expected-error{{initializer 'init(_:)' requires the types 'W<String>' and 'W<Int>' be equivalent}}
|
||||
let _ = S<[W<String>]>.f(W<[Int]>()) // expected-error{{static method 'f' requires the types 'W<String>' and 'W<Int>' be equivalent}}
|
||||
let _ = S<[W<String>]>().instancef(W<[Int]>()) // expected-error{{instance method 'instancef' requires the types 'W<String>' and 'W<Int>' be equivalent}}
|
||||
|
||||
// Archetypes requirement failure
|
||||
func genericFunc<C1: Collection, C2: Collection>(_ c2: W<C2>, c1: C1.Type) where C1.Element == W<C2.Element> {
|
||||
|
||||
@@ -315,15 +315,15 @@ func testDependentTypeInClosure() {
|
||||
// DEPENDENT_IN_CLOSURE_3-DAG: Decl[Constructor]/CurrNominal/TypeRelation[Convertible]: init({#arg: DataType#}, {#fn: () -> Data.Content##() -> Data.Content#})[#DependentTypeInClosure<DataType>#];
|
||||
|
||||
let _ = DependentTypeInClosure(#^DEPENDENT_IN_CLOSURE_1^#)
|
||||
// DEPENDENT_IN_CLOSURE_1-DAG: Decl[Constructor]/CurrNominal/Flair[ArgLabels]: ['(']{#(arg): DataType#}, {#fn: (_) -> Void##(_) -> Void#}[')'][#DependentTypeInClosure<DataType>#];
|
||||
// DEPENDENT_IN_CLOSURE_1-DAG: Decl[Constructor]/CurrNominal/Flair[ArgLabels]: ['(']{#arg: DataType#}, {#fn: () -> _##() -> _#}[')'][#DependentTypeInClosure<DataType>#];
|
||||
// DEPENDENT_IN_CLOSURE_1-DAG: Decl[Constructor]/CurrNominal/Flair[ArgLabels]: ['(']{#(arg): DataType#}, {#fn: (Data.Content) -> Void##(Data.Content) -> Void#}[')'][#DependentTypeInClosure<DataType>#];
|
||||
// DEPENDENT_IN_CLOSURE_1-DAG: Decl[Constructor]/CurrNominal/Flair[ArgLabels]: ['(']{#arg: DataType#}, {#fn: () -> Data.Content##() -> Data.Content#}[')'][#DependentTypeInClosure<DataType>#];
|
||||
|
||||
let _ = DependentTypeInClosure.#^DEPENDENT_IN_CLOSURE_2^#
|
||||
// DEPENDENT_IN_CLOSURE_2: Begin completions, 4 items
|
||||
// DEPENDENT_IN_CLOSURE_2-DAG: Keyword[self]/CurrNominal: self[#DependentTypeInClosure<_>.Type#]; name=self
|
||||
// DEPENDENT_IN_CLOSURE_2-DAG: Keyword/CurrNominal: Type[#DependentTypeInClosure<_>.Type#]; name=Type
|
||||
// DEPENDENT_IN_CLOSURE_2-DAG: Decl[Constructor]/CurrNominal: init({#(arg): _#}, {#fn: (_.Content) -> Void##(_.Content) -> Void#})[#DependentTypeInClosure<_>#]; name=init(:fn:)
|
||||
// DEPENDENT_IN_CLOSURE_2-DAG: Decl[Constructor]/CurrNominal: init({#arg: _#}, {#fn: () -> _.Content##() -> _.Content#})[#DependentTypeInClosure<_>#]; name=init(arg:fn:)
|
||||
// DEPENDENT_IN_CLOSURE_2-DAG: Keyword[self]/CurrNominal: self[#DependentTypeInClosure<Data>.Type#]; name=self
|
||||
// DEPENDENT_IN_CLOSURE_2-DAG: Keyword/CurrNominal: Type[#DependentTypeInClosure<Data>.Type#]; name=Type
|
||||
// DEPENDENT_IN_CLOSURE_2-DAG: Decl[Constructor]/CurrNominal: init({#(arg): Data#}, {#fn: (Data.Content) -> Void##(Data.Content) -> Void#})[#DependentTypeInClosure<Data>#]; name=init(:fn:)
|
||||
// DEPENDENT_IN_CLOSURE_2-DAG: Decl[Constructor]/CurrNominal: init({#arg: Data#}, {#fn: () -> Data.Content##() -> Data.Content#})[#DependentTypeInClosure<Data>#]; name=init(arg:fn:)
|
||||
}
|
||||
struct InitWithUnresolved<Data: DataType> where Data.Content: Comparable {
|
||||
init(arg: Data, fn: (Data.Content) -> Void) {}
|
||||
@@ -334,7 +334,7 @@ extension InitWithUnresolved where Self.Data: Comparable {
|
||||
func testInitWithUnresolved() {
|
||||
let _ = InitWithUnresolved(#^INIT_WITH_UNRESOLVEDTYPE_1^#
|
||||
// INIT_WITH_UNRESOLVEDTYPE_1: Begin completions, 2 items
|
||||
// INIT_WITH_UNRESOLVEDTYPE_1-DAG: Decl[Constructor]/CurrNominal/Flair[ArgLabels]: ['(']{#arg: DataType#}, {#fn: (_) -> Void##(_) -> Void#}[')'][#InitWithUnresolved<DataType>#];
|
||||
// INIT_WITH_UNRESOLVEDTYPE_1-DAG: Decl[Constructor]/CurrNominal/Flair[ArgLabels]: ['(']{#arg: DataType#}, {#fn: (Data.Content) -> Void##(Data.Content) -> Void#}[')'][#InitWithUnresolved<DataType>#];
|
||||
// INIT_WITH_UNRESOLVEDTYPE_1-DAG: Decl[Constructor]/CurrNominal/Flair[ArgLabels]: ['(']{#arg2: DataType#}[')'][#InitWithUnresolved<DataType>#];
|
||||
}
|
||||
|
||||
|
||||
@@ -381,6 +381,6 @@ extension P_80635105 {
|
||||
func test_80635105() {
|
||||
let fn = { x in
|
||||
S_80635105.#^RDAR_80635105^#
|
||||
// RDAR_80635105: Decl[InstanceMethod]/Super: foo({#(self): S_80635105<_>#})[#(P_80635105.T) -> Void#]; name=foo
|
||||
// RDAR_80635105: Decl[InstanceMethod]/Super: foo({#(self): S_80635105<T>#})[#(P_80635105.T) -> Void#]; name=foo
|
||||
}
|
||||
}
|
||||
|
||||
@@ -153,14 +153,14 @@ enum BazEnum<T> {
|
||||
// BAZ_INT_ENUM_NO_DOT-DAG: Keyword[self]/CurrNominal: .self[#BazEnum<Int>.Type#]; name=self
|
||||
// BAZ_INT_ENUM_NO_DOT-DAG: Keyword/CurrNominal: .Type[#BazEnum<Int>.Type#]; name=Type
|
||||
|
||||
// BAZ_T_ENUM_NO_DOT-DAG: Decl[EnumElement]/CurrNominal: .Baz1[#BazEnum<_>#]{{; name=.+$}}
|
||||
// BAZ_T_ENUM_NO_DOT-DAG: Decl[EnumElement]/CurrNominal: .Baz2({#_#})[#BazEnum<_>#]{{; name=.+$}}
|
||||
// BAZ_T_ENUM_NO_DOT-DAG: Decl[InstanceMethod]/CurrNominal: .bazInstanceFunc({#(self): &BazEnum<_>#})[#() -> Void#]{{; name=.+$}}
|
||||
// BAZ_T_ENUM_NO_DOT-DAG: Decl[EnumElement]/CurrNominal: .Baz1[#BazEnum<T>#]{{; name=.+$}}
|
||||
// BAZ_T_ENUM_NO_DOT-DAG: Decl[EnumElement]/CurrNominal: .Baz2({#T#})[#BazEnum<T>#]{{; name=.+$}}
|
||||
// BAZ_T_ENUM_NO_DOT-DAG: Decl[InstanceMethod]/CurrNominal: .bazInstanceFunc({#(self): &BazEnum<T>#})[#() -> Void#]{{; name=.+$}}
|
||||
// BAZ_T_ENUM_NO_DOT-DAG: Decl[StaticVar]/CurrNominal: .staticVar[#Int#]{{; name=.+$}}
|
||||
// BAZ_T_ENUM_NO_DOT-DAG: Decl[StaticVar]/CurrNominal: .staticVarT[#_#]{{; name=.+$}}
|
||||
// BAZ_T_ENUM_NO_DOT-DAG: Decl[StaticVar]/CurrNominal: .staticVarT[#T#]{{; name=.+$}}
|
||||
// BAZ_T_ENUM_NO_DOT-DAG: Decl[StaticMethod]/CurrNominal/TypeRelation[Invalid]: .bazStaticFunc()[#Void#]{{; name=.+$}}
|
||||
// BAZ_T_ENUM_NO_DOT-DAG: Keyword[self]/CurrNominal: .self[#BazEnum<_>.Type#]; name=self
|
||||
// BAZ_T_ENUM_NO_DOT-DAG: Keyword/CurrNominal: .Type[#BazEnum<_>.Type#]; name=Type
|
||||
// BAZ_T_ENUM_NO_DOT-DAG: Keyword[self]/CurrNominal: .self[#BazEnum<T>.Type#]; name=self
|
||||
// BAZ_T_ENUM_NO_DOT-DAG: Keyword/CurrNominal: .Type[#BazEnum<T>.Type#]; name=Type
|
||||
|
||||
// BAZ_INT_ENUM_DOT: Begin completions, 8 items
|
||||
// BAZ_INT_ENUM_DOT-DAG: Keyword[self]/CurrNominal: self[#BazEnum<Int>.Type#]; name=self
|
||||
@@ -173,13 +173,13 @@ enum BazEnum<T> {
|
||||
// BAZ_INT_ENUM_DOT-DAG: Decl[StaticMethod]/CurrNominal/TypeRelation[Invalid]: bazStaticFunc()[#Void#]{{; name=.+$}}
|
||||
|
||||
// BAZ_T_ENUM_DOT: Begin completions, 8 items
|
||||
// BAZ_T_ENUM_DOT-DAG: Keyword[self]/CurrNominal: self[#BazEnum<_>.Type#]; name=self
|
||||
// BAZ_T_ENUM_DOT-DAG: Keyword/CurrNominal: Type[#BazEnum<_>.Type#]; name=Type
|
||||
// BAZ_T_ENUM_DOT-DAG: Decl[EnumElement]/CurrNominal: Baz1[#BazEnum<_>#]{{; name=.+$}}
|
||||
// BAZ_T_ENUM_DOT-DAG: Decl[EnumElement]/CurrNominal: Baz2({#_#})[#BazEnum<_>#]{{; name=.+$}}
|
||||
// BAZ_T_ENUM_DOT-DAG: Decl[InstanceMethod]/CurrNominal: bazInstanceFunc({#(self): &BazEnum<_>#})[#() -> Void#]{{; name=.+$}}
|
||||
// BAZ_T_ENUM_DOT-DAG: Keyword[self]/CurrNominal: self[#BazEnum<T>.Type#]; name=self
|
||||
// BAZ_T_ENUM_DOT-DAG: Keyword/CurrNominal: Type[#BazEnum<T>.Type#]; name=Type
|
||||
// BAZ_T_ENUM_DOT-DAG: Decl[EnumElement]/CurrNominal: Baz1[#BazEnum<T>#]{{; name=.+$}}
|
||||
// BAZ_T_ENUM_DOT-DAG: Decl[EnumElement]/CurrNominal: Baz2({#T#})[#BazEnum<T>#]{{; name=.+$}}
|
||||
// BAZ_T_ENUM_DOT-DAG: Decl[InstanceMethod]/CurrNominal: bazInstanceFunc({#(self): &BazEnum<T>#})[#() -> Void#]{{; name=.+$}}
|
||||
// BAZ_T_ENUM_DOT-DAG: Decl[StaticVar]/CurrNominal: staticVar[#Int#]{{; name=.+$}}
|
||||
// BAZ_T_ENUM_DOT-DAG: Decl[StaticVar]/CurrNominal: staticVarT[#_#]{{; name=.+$}}
|
||||
// BAZ_T_ENUM_DOT-DAG: Decl[StaticVar]/CurrNominal: staticVarT[#T#]{{; name=.+$}}
|
||||
// BAZ_T_ENUM_DOT-DAG: Decl[StaticMethod]/CurrNominal/TypeRelation[Invalid]: bazStaticFunc()[#Void#]{{; name=.+$}}
|
||||
|
||||
enum QuxEnum : Int {
|
||||
|
||||
@@ -98,16 +98,16 @@ func testCompleteModuleQualified2() {
|
||||
func testCompleteModuleQualified3() {
|
||||
foo_swift_module.BarGenericSwiftStruct1#^MODULE_QUALIFIED_3^#
|
||||
}
|
||||
// MODULE_QUALIFIED_3-DAG: Decl[Constructor]/CurrNominal/Flair[ArgLabels]: ({#t: _#})[#BarGenericSwiftStruct1<_>#]; name=(t:)
|
||||
// MODULE_QUALIFIED_3-DAG: Decl[InstanceMethod]/CurrNominal: .bar1InstanceFunc({#(self): BarGenericSwiftStruct1<_>#})[#() -> Void#]; name=bar1InstanceFunc(:)
|
||||
// MODULE_QUALIFIED_3-DAG: Decl[Constructor]/CurrNominal/Flair[ArgLabels]: ({#t: T#})[#BarGenericSwiftStruct1<T>#]; name=(t:)
|
||||
// MODULE_QUALIFIED_3-DAG: Decl[InstanceMethod]/CurrNominal: .bar1InstanceFunc({#(self): BarGenericSwiftStruct1<T>#})[#() -> Void#]; name=bar1InstanceFunc(:)
|
||||
|
||||
func testCompleteModuleQualified4() {
|
||||
foo_swift_module.BarGenericSwiftStruct2#^MODULE_QUALIFIED_4^#
|
||||
}
|
||||
// MODULE_QUALIFIED_4-DAG: Decl[Constructor]/CurrNominal/Flair[ArgLabels]: ({#t: _#}, {#u: _#})[#BarGenericSwiftStruct2<_, _>#]; name=(t:u:)
|
||||
// MODULE_QUALIFIED_4-DAG: Decl[InstanceMethod]/CurrNominal: .bar2InstanceFunc({#(self): BarGenericSwiftStruct2<_, _>#})[#() -> Void#]; name=bar2InstanceFunc(:)
|
||||
// MODULE_QUALIFIED_4-DAG: Keyword[self]/CurrNominal: .self[#BarGenericSwiftStruct2<_, _>.Type#]; name=self
|
||||
// MODULE_QUALIFIED_4-DAG: Keyword/CurrNominal: .Type[#BarGenericSwiftStruct2<_, _>.Type#]; name=Type
|
||||
// MODULE_QUALIFIED_4-DAG: Decl[Constructor]/CurrNominal/Flair[ArgLabels]: ({#t: T#}, {#u: U#})[#BarGenericSwiftStruct2<T, U>#]; name=(t:u:)
|
||||
// MODULE_QUALIFIED_4-DAG: Decl[InstanceMethod]/CurrNominal: .bar2InstanceFunc({#(self): BarGenericSwiftStruct2<T, U>#})[#() -> Void#]; name=bar2InstanceFunc(:)
|
||||
// MODULE_QUALIFIED_4-DAG: Keyword[self]/CurrNominal: .self[#BarGenericSwiftStruct2<T, U>.Type#]; name=self
|
||||
// MODULE_QUALIFIED_4-DAG: Keyword/CurrNominal: .Type[#BarGenericSwiftStruct2<T, U>.Type#]; name=Type
|
||||
|
||||
func testCompleteModuleQualified5() {
|
||||
corrupted_module.#^MODULE_QUALIFIED_5^#
|
||||
|
||||
@@ -45,8 +45,8 @@ extension ObservableConvertibleType {
|
||||
return CatchSequence.#^CATCHSEQUENCE_DOT^#
|
||||
}
|
||||
}
|
||||
// CATCHSEQUENCE_DOT-DAG: Keyword[self]/CurrNominal: self[#CatchSequence<_>.Type#]; name=self
|
||||
// CATCHSEQUENCE_DOT-DAG: Keyword/CurrNominal: Type[#CatchSequence<_>.Type#]; name=Type
|
||||
// CATCHSEQUENCE_DOT-DAG: Decl[Constructor]/CurrNominal/TypeRelation[Convertible]: init()[#CatchSequence<_>#]; name=init()
|
||||
// CATCHSEQUENCE_DOT-DAG: Decl[StaticMethod]/Super/TypeRelation[Convertible]: catchError()[#Observable<CatchSequence<_>.T>#]; name=catchError()
|
||||
// CATCHSEQUENCE_DOT-DAG: Decl[TypeAlias]/Super: T[#Observable<_.Element.T>.T#]; name=T
|
||||
// CATCHSEQUENCE_DOT-DAG: Keyword[self]/CurrNominal: self[#CatchSequence<S>.Type#]; name=self
|
||||
// CATCHSEQUENCE_DOT-DAG: Keyword/CurrNominal: Type[#CatchSequence<S>.Type#]; name=Type
|
||||
// CATCHSEQUENCE_DOT-DAG: Decl[Constructor]/CurrNominal/TypeRelation[Convertible]: init()[#CatchSequence<S>#]; name=init()
|
||||
// CATCHSEQUENCE_DOT-DAG: Decl[StaticMethod]/Super/TypeRelation[Convertible]: catchError()[#Observable<CatchSequence<S>.T>#]; name=catchError()
|
||||
// CATCHSEQUENCE_DOT-DAG: Decl[TypeAlias]/Super: T[#Observable<S.Element.T>.T#]; name=T
|
||||
|
||||
@@ -12,10 +12,10 @@ struct MyStruct<T> {
|
||||
func test1() {
|
||||
let _ = MyStruct #^METATYPE_UNRESOLVED^#
|
||||
// METATYPE_UNRESOLVED: Begin completions, 4 items
|
||||
// METATYPE_UNRESOLVED-DAG: Decl[Subscript]/CurrNominal: [{#(x): Int#}, {#static: _#}][#MyStruct<_>#];
|
||||
// METATYPE_UNRESOLVED-DAG: Decl[Constructor]/CurrNominal/Flair[ArgLabels]: ()[#MyStruct<_>#];
|
||||
// METATYPE_UNRESOLVED-DAG: Keyword[self]/CurrNominal: .self[#MyStruct<_>.Type#];
|
||||
// METATYPE_UNRESOLVED-DAG: Keyword/CurrNominal: .Type[#MyStruct<_>.Type#];
|
||||
// METATYPE_UNRESOLVED-DAG: Decl[Subscript]/CurrNominal: [{#(x): Int#}, {#static: T#}][#MyStruct<T>#];
|
||||
// METATYPE_UNRESOLVED-DAG: Decl[Constructor]/CurrNominal/Flair[ArgLabels]: ()[#MyStruct<T>#];
|
||||
// METATYPE_UNRESOLVED-DAG: Keyword[self]/CurrNominal: .self[#MyStruct<T>.Type#];
|
||||
// METATYPE_UNRESOLVED-DAG: Keyword/CurrNominal: .Type[#MyStruct<T>.Type#];
|
||||
|
||||
let _ = MyStruct[#^METATYPE_UNRESOLVED_BRACKET^#
|
||||
// METATYPE_UNRESOLVED_BRACKET-DAG: Decl[Subscript]/CurrNominal/Flair[ArgLabels]: ['[']{#(x): Int#}, {#static: T#}[']'][#MyStruct<T>#];
|
||||
|
||||
@@ -15,4 +15,4 @@ _ = S2()#^UNINFERRED^#
|
||||
|
||||
// UNINFERRED-DAG: Decl[Subscript]/Super: [{#(v0): T#}][#Int#]; name=[:]
|
||||
// UNINFERRED-DAG: Decl[Subscript]/Super: [{#(v0): T#}][#_#]; name=[:]
|
||||
// UNINFERRED-DAG: Keyword[self]/CurrNominal: .self[#S2<_>#]; name=self
|
||||
// UNINFERRED-DAG: Keyword[self]/CurrNominal: .self[#S2<T>#]; name=self
|
||||
|
||||
@@ -1074,19 +1074,19 @@ class BuilderStyle<T> {
|
||||
func testTypeCheckWithUnsolvedVariables1() {
|
||||
BuilderStyle().#^TC_UNSOLVED_VARIABLES_1^#
|
||||
}
|
||||
// TC_UNSOLVED_VARIABLES_1-DAG: Keyword[self]/CurrNominal: self[#BuilderStyle<_>#]; name=self
|
||||
// TC_UNSOLVED_VARIABLES_1-DAG: Keyword[self]/CurrNominal: self[#BuilderStyle<T>#]; name=self
|
||||
// TC_UNSOLVED_VARIABLES_1-DAG: Decl[InstanceVar]/CurrNominal: count[#Int#]{{; name=.+$}}
|
||||
// TC_UNSOLVED_VARIABLES_1-DAG: Decl[InstanceMethod]/CurrNominal: addString({#(s): String#})[#BuilderStyle<_>#]{{; name=.+$}}
|
||||
// TC_UNSOLVED_VARIABLES_1-DAG: Decl[InstanceMethod]/CurrNominal: add({#(t): _#})[#BuilderStyle<_>#]{{; name=.+$}}
|
||||
// TC_UNSOLVED_VARIABLES_1-DAG: Decl[InstanceMethod]/CurrNominal: addString({#(s): String#})[#BuilderStyle<T>#]{{; name=.+$}}
|
||||
// TC_UNSOLVED_VARIABLES_1-DAG: Decl[InstanceMethod]/CurrNominal: add({#(t): T#})[#BuilderStyle<T>#]{{; name=.+$}}
|
||||
// TC_UNSOLVED_VARIABLES_1-DAG: Decl[InstanceMethod]/CurrNominal: get()[#Int#]{{; name=.+$}}
|
||||
|
||||
func testTypeCheckWithUnsolvedVariables2() {
|
||||
BuilderStyle().addString("abc").#^TC_UNSOLVED_VARIABLES_2^#
|
||||
}
|
||||
// TC_UNSOLVED_VARIABLES_2-DAG: Keyword[self]/CurrNominal: self[#BuilderStyle<_>#]; name=self
|
||||
// TC_UNSOLVED_VARIABLES_2-DAG: Keyword[self]/CurrNominal: self[#BuilderStyle<T>#]; name=self
|
||||
// TC_UNSOLVED_VARIABLES_2-DAG: Decl[InstanceVar]/CurrNominal: count[#Int#]{{; name=.+$}}
|
||||
// TC_UNSOLVED_VARIABLES_2-DAG: Decl[InstanceMethod]/CurrNominal: addString({#(s): String#})[#BuilderStyle<_>#]{{; name=.+$}}
|
||||
// TC_UNSOLVED_VARIABLES_2-DAG: Decl[InstanceMethod]/CurrNominal: add({#(t): _#})[#BuilderStyle<_>#]{{; name=.+$}}
|
||||
// TC_UNSOLVED_VARIABLES_2-DAG: Decl[InstanceMethod]/CurrNominal: addString({#(s): String#})[#BuilderStyle<T>#]{{; name=.+$}}
|
||||
// TC_UNSOLVED_VARIABLES_2-DAG: Decl[InstanceMethod]/CurrNominal: add({#(t): T#})[#BuilderStyle<T>#]{{; name=.+$}}
|
||||
// TC_UNSOLVED_VARIABLES_2-DAG: Decl[InstanceMethod]/CurrNominal: get()[#Int#]{{; name=.+$}}
|
||||
|
||||
func testTypeCheckWithUnsolvedVariables3() {
|
||||
|
||||
@@ -56,7 +56,7 @@ class A {
|
||||
var a: MyArray<Int>
|
||||
init() {
|
||||
a = MyArray<Int // expected-error {{generic parameter 'Element' could not be inferred}} expected-note {{explicitly specify the generic arguments to fix this issue}}
|
||||
// expected-error@-1 {{binary operator '<' cannot be applied to operands of type 'MyArray<_>.Type' and 'Int.Type'}}
|
||||
// expected-error@-1 {{binary operator '<' cannot be applied to operands of type 'MyArray<Element>.Type' and 'Int.Type'}}
|
||||
// expected-error@-2 {{cannot assign value of type 'Bool' to type 'MyArray<Int>'}}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ do {
|
||||
let exist2: any UnfulfillableGenericRequirementsDerived2
|
||||
|
||||
exist1.method4(false)
|
||||
// expected-error@-1 {{instance method 'method4' requires that 'Bool' inherit from 'Class<Self.A>}}
|
||||
// expected-error@-1 {{instance method 'method4' requires that 'Bool' inherit from 'Class<Bool>}}
|
||||
exist2.method4(false)
|
||||
// expected-error@-1 {{member 'method4' cannot be used on value of type 'any UnfulfillableGenericRequirementsDerived2'; consider using a generic constraint instead}}
|
||||
// expected-error@-2 {{instance method 'method4' requires that 'Bool' inherit from 'Class<Self.A>'}}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
// {"kind":"complete","original":"d09c9cf7","signature":"swift::Mangle::ASTMangler::mangleTypeAsUSR(swift::Type)"}
|
||||
// RUN: %target-swift-ide-test -code-completion -batch-code-completion -skip-filecheck -code-completion-diagnostics -source-filename %s
|
||||
try #^^# ?? (try? a.() as? b)
|
||||
@@ -9,7 +9,7 @@ struct MyView: View {
|
||||
|
||||
var body: some View {
|
||||
Table(self.data) {
|
||||
// expected-error@-1 {{expected expression in result builder 'TableColumnBuilder'}} {{23-23=<#result#>}}
|
||||
// expected-error@-1 {{expected expression of type 'Columns' in result builder 'TableColumnBuilder'}} {{23-23=<#T##Columns#>}}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ struct Empty {
|
||||
init() {}
|
||||
}
|
||||
|
||||
struct Test<T> where T : P { // expected-note {{where 'T' = 'Generic<(Empty, _)>'}}
|
||||
struct Test<T> where T : P { // expected-note {{where 'T' = 'Generic<(Empty, C1)>'}}
|
||||
init(@Builder _: () -> T) {}
|
||||
}
|
||||
|
||||
@@ -34,5 +34,5 @@ let x = G {
|
||||
Test { Empty() }
|
||||
// expected-error@-1 {{static method 'buildBlock' requires that 'Empty' conform to 'P'}}
|
||||
// expected-error@-2 {{missing argument for parameter #2 in call}}
|
||||
// expected-error@-3 {{generic struct 'Test' requires that 'Generic<(Empty, _)>' conform to 'P'}}
|
||||
// expected-error@-3 {{generic struct 'Test' requires that 'Generic<(Empty, C1)>' conform to 'P'}}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user