diff --git a/include/swift/Sema/CSFix.h b/include/swift/Sema/CSFix.h index 581c537cf4964..fa4fef8aa2ea9 100644 --- a/include/swift/Sema/CSFix.h +++ b/include/swift/Sema/CSFix.h @@ -295,6 +295,13 @@ enum class FixKind : uint8_t { /// Ignore result builder body if it has `return` statements. IgnoreResultBuilderWithReturnStmts, + /// Ignore `ErrorExpr` or `ErrorType` during pre-check. + IgnoreInvalidASTNode, + + /// Ignore a named pattern whose type we couldn't infer. This issue should + /// already have been diagnosed elsewhere. + IgnoreInvalidNamedPattern, + /// Resolve type of `nil` by providing a contextual type. SpecifyContextualTypeForNil, @@ -707,6 +714,26 @@ class ContextualMismatch : public ConstraintFix { bool diagnose(const Solution &solution, bool asNote = false) const override; + bool coalesceAndDiagnose(const Solution &solution, + ArrayRef secondaryFixes, + bool asNote = false) const override { + // If the from type or to type is a placeholer type that corresponds to an + // ErrorExpr, the issue has already been diagnosed. There's no need to + // produce another diagnostic for the contextual mismatch complainting that + // a type is not convertible to a placeholder type. + if (auto fromPlaceholder = getFromType()->getAs()) { + if (fromPlaceholder->getOriginator().is()) { + return true; + } + } + if (auto toPlaceholder = getToType()->getAs()) { + if (toPlaceholder->getOriginator().is()) { + return true; + } + } + return ConstraintFix::coalesceAndDiagnose(solution, secondaryFixes, asNote); + } + bool diagnoseForAmbiguity(CommonFixesArray commonFixes) const override; static ContextualMismatch *create(ConstraintSystem &cs, Type lhs, Type rhs, @@ -2693,6 +2720,57 @@ class IgnoreResultBuilderWithReturnStmts final } }; +class IgnoreInvalidASTNode final : public ConstraintFix { + IgnoreInvalidASTNode(ConstraintSystem &cs, ConstraintLocator *locator) + : IgnoreInvalidASTNode(cs, FixKind::IgnoreInvalidASTNode, locator) {} + +protected: + IgnoreInvalidASTNode(ConstraintSystem &cs, FixKind kind, + ConstraintLocator *locator) + : ConstraintFix(cs, kind, locator) {} + +public: + std::string getName() const override { return "ignore invalid AST node"; } + + bool diagnose(const Solution &solution, bool asNote = false) const override; + + bool diagnoseForAmbiguity(CommonFixesArray commonFixes) const override { + return diagnose(*commonFixes.front().first); + } + + static IgnoreInvalidASTNode *create(ConstraintSystem &cs, + ConstraintLocator *locator); + + static bool classof(ConstraintFix *fix) { + return fix->getKind() == FixKind::IgnoreInvalidASTNode; + } +}; + +class IgnoreInvalidNamedPattern final : public ConstraintFix { + IgnoreInvalidNamedPattern(ConstraintSystem &cs, NamedPattern *pattern, + ConstraintLocator *locator) + : ConstraintFix(cs, FixKind::IgnoreInvalidNamedPattern, locator) {} + +public: + std::string getName() const override { + return "specify type for pattern match"; + } + + bool diagnose(const Solution &solution, bool asNote = false) const override; + + bool diagnoseForAmbiguity(CommonFixesArray commonFixes) const override { + return diagnose(*commonFixes.front().first); + } + + static IgnoreInvalidNamedPattern *create(ConstraintSystem &cs, + NamedPattern *pattern, + ConstraintLocator *locator); + + static bool classof(ConstraintFix *fix) { + return fix->getKind() == FixKind::IgnoreInvalidNamedPattern; + } +}; + class SpecifyContextualTypeForNil final : public ConstraintFix { SpecifyContextualTypeForNil(ConstraintSystem &cs, ConstraintLocator *locator) diff --git a/include/swift/Sema/ConstraintLocatorPathElts.def b/include/swift/Sema/ConstraintLocatorPathElts.def index 715d028340660..1a7664cd70660 100644 --- a/include/swift/Sema/ConstraintLocatorPathElts.def +++ b/include/swift/Sema/ConstraintLocatorPathElts.def @@ -239,6 +239,9 @@ CUSTOM_LOCATOR_PATH_ELT(SyntacticElement) /// The element of the pattern binding declaration. CUSTOM_LOCATOR_PATH_ELT(PatternBindingElement) +/// The variable declared by a named pattern. +SIMPLE_LOCATOR_PATH_ELT(NamedPatternDecl) + #undef LOCATOR_PATH_ELT #undef CUSTOM_LOCATOR_PATH_ELT #undef SIMPLE_LOCATOR_PATH_ELT diff --git a/include/swift/Sema/ConstraintSystem.h b/include/swift/Sema/ConstraintSystem.h index d5bd9c8917dac..d5e2bc4465d94 100644 --- a/include/swift/Sema/ConstraintSystem.h +++ b/include/swift/Sema/ConstraintSystem.h @@ -640,6 +640,13 @@ T *getAsStmt(ASTNode node) { return nullptr; } +template +T *getAsPattern(ASTNode node) { + if (auto *P = node.dyn_cast()) + return dyn_cast_or_null(P); + return nullptr; +} + SourceLoc getLoc(ASTNode node); SourceRange getSourceRange(ASTNode node); diff --git a/lib/Sema/CSBindings.cpp b/lib/Sema/CSBindings.cpp index 518c74ebc1498..7a2ccb1142b64 100644 --- a/lib/Sema/CSBindings.cpp +++ b/lib/Sema/CSBindings.cpp @@ -109,6 +109,16 @@ bool BindingSet::isDelayed() const { if (locator->directlyAt()) return true; + // When inferring the type of a variable in a pattern, delay its resolution + // so that we resolve type variables inside the expression as placeholders + // instead of marking the type of the variable itself as a placeholder. This + // allows us to produce more specific errors because the type variable in + // the expression that introduced the placeholder might be diagnosable using + // fixForHole. + if (locator->isLastElement()) { + return true; + } + // It's possible that type of member couldn't be determined, // and if so it would be beneficial to bind member to a hole // early to propagate that information down to arguments, @@ -1979,6 +1989,20 @@ TypeVariableBinding::fixForHole(ConstraintSystem &cs) const { return std::make_pair(fix, /*impact=*/(unsigned)10); } + if (auto pattern = getAsPattern(dstLocator->getAnchor())) { + if (dstLocator->getPath().size() == 1 && + dstLocator->isLastElement()) { + // Not being able to infer the type of a variable in a pattern binding + // decl is more dramatic than anything that could happen inside the + // expression because we want to preferrably point the diagnostic to a + // part of the expression that caused us to be unable to infer the + // variable's type. + ConstraintFix *fix = + IgnoreInvalidNamedPattern::create(cs, pattern, dstLocator); + return std::make_pair(fix, /*impact=*/(unsigned)100); + } + } + return None; } diff --git a/lib/Sema/CSFix.cpp b/lib/Sema/CSFix.cpp index 64ecfb1d6fded..d1f069b6d6b69 100644 --- a/lib/Sema/CSFix.cpp +++ b/lib/Sema/CSFix.cpp @@ -1945,6 +1945,16 @@ IgnoreInvalidResultBuilderBody::create(ConstraintSystem &cs, return new (cs.getAllocator()) IgnoreInvalidResultBuilderBody(cs, locator); } +bool IgnoreInvalidASTNode::diagnose(const Solution &solution, + bool asNote) const { + return true; // Already diagnosed by the producer of ErrorExpr or ErrorType. +} + +IgnoreInvalidASTNode *IgnoreInvalidASTNode::create(ConstraintSystem &cs, + ConstraintLocator *locator) { + return new (cs.getAllocator()) IgnoreInvalidASTNode(cs, locator); +} + bool SpecifyContextualTypeForNil::diagnose(const Solution &solution, bool asNote) const { MissingContextualTypeForNil failure(solution, getLocator()); @@ -1994,6 +2004,20 @@ IgnoreResultBuilderWithReturnStmts::create(ConstraintSystem &cs, Type builderTy, IgnoreResultBuilderWithReturnStmts(cs, builderTy, locator); } +bool IgnoreInvalidNamedPattern::diagnose(const Solution &solution, + bool asNote) const { + // Not being able to infer the type of a pattern should already have been + // diagnosed on the pattern's initializer or as a structural issue of the AST. + return true; +} + +IgnoreInvalidNamedPattern * +IgnoreInvalidNamedPattern::create(ConstraintSystem &cs, NamedPattern *pattern, + ConstraintLocator *locator) { + return new (cs.getAllocator()) + IgnoreInvalidNamedPattern(cs, pattern, locator); +} + bool SpecifyBaseTypeForOptionalUnresolvedMember::diagnose( const Solution &solution, bool asNote) const { MemberMissingExplicitBaseTypeFailure failure(solution, MemberName, diff --git a/lib/Sema/CSGen.cpp b/lib/Sema/CSGen.cpp index 1d76630405e48..77bb863b32d1d 100644 --- a/lib/Sema/CSGen.cpp +++ b/lib/Sema/CSGen.cpp @@ -890,6 +890,11 @@ namespace { // that member through the base returns a value convertible to the type // of this expression. auto baseTy = CS.getType(base); + if (isa(base)) { + return CS.createTypeVariable( + CS.getConstraintLocator(expr, ConstraintLocator::Member), + TVO_CanBindToHole); + } auto tv = CS.createTypeVariable( CS.getConstraintLocator(expr, ConstraintLocator::Member), TVO_CanBindToLValue | TVO_CanBindToNoEscape); @@ -1068,19 +1073,11 @@ namespace { ConstraintSystem &getConstraintSystem() const { return CS; } virtual Type visitErrorExpr(ErrorExpr *E) { - if (!CS.isForCodeCompletion()) - return nullptr; - - // For code completion, treat error expressions that don't contain - // the completion location itself as holes. If an ErrorExpr contains the - // code completion location, a fallback typecheck is called on the - // ErrorExpr's OriginalExpr (valid sub-expression) if it had one, - // independent of the wider expression containing the ErrorExpr, so - // there's no point attempting to produce a solution for it. - if (CS.containsCodeCompletionLoc(E)) - return nullptr; + CS.recordFix( + IgnoreInvalidASTNode::create(CS, CS.getConstraintLocator(E))); - return PlaceholderType::get(CS.getASTContext(), E); + return CS.createTypeVariable(CS.getConstraintLocator(E), + TVO_CanBindToHole); } virtual Type visitCodeCompletionExpr(CodeCompletionExpr *E) { @@ -1374,7 +1371,11 @@ namespace { const auto result = TypeResolution::resolveContextualType( repr, CS.DC, resCtx, genericOpener, placeholderHandler); if (result->hasError()) { - return Type(); + CS.recordFix( + IgnoreInvalidASTNode::create(CS, CS.getConstraintLocator(locator))); + + return CS.createTypeVariable(CS.getConstraintLocator(repr), + TVO_CanBindToHole); } // Diagnose top-level usages of placeholder types. if (isa(repr->getWithoutParens())) { @@ -1600,7 +1601,11 @@ namespace { Type visitUnresolvedSpecializeExpr(UnresolvedSpecializeExpr *expr) { auto baseTy = CS.getType(expr->getSubExpr()); - + + if (baseTy->isTypeVariableOrMember()) { + return baseTy; + } + // We currently only support explicit specialization of generic types. // FIXME: We could support explicit function specialization. auto &de = CS.getASTContext().Diags; @@ -2322,8 +2327,10 @@ namespace { } if (!varType) { - varType = CS.createTypeVariable(CS.getConstraintLocator(locator), - TVO_CanBindToNoEscape); + varType = CS.createTypeVariable( + CS.getConstraintLocator(pattern, + LocatorPathElt::NamedPatternDecl()), + TVO_CanBindToNoEscape | TVO_CanBindToHole); // If this is either a `weak` declaration or capture e.g. // `weak var ...` or `[weak self]`. Let's wrap type variable diff --git a/lib/Sema/CSSimplify.cpp b/lib/Sema/CSSimplify.cpp index 49e2a039aa991..9fce8cb5ecd1c 100644 --- a/lib/Sema/CSSimplify.cpp +++ b/lib/Sema/CSSimplify.cpp @@ -11211,18 +11211,6 @@ ConstraintSystem::simplifyApplicableFnConstraint( // following: $T1 -> $T2. auto func1 = type1->castTo(); - // If a type variable representing "function type" is a hole - // or it could be bound to some concrete type with a help of - // a fix, let's propagate holes to the "input" type. Doing so - // provides more information to upcoming argument and result matching. - if (shouldAttemptFixes()) { - if (auto *typeVar = type2->getAs()) { - auto *locator = typeVar->getImpl().getLocator(); - if (typeVar->isPlaceholder() || hasFixFor(locator)) - recordAnyTypeVarAsPotentialHole(func1); - } - } - // Before stripping lvalue-ness and optional types, save the original second // type for handling `func callAsFunction` and `@dynamicCallable` // applications. This supports the following cases: @@ -11237,6 +11225,29 @@ ConstraintSystem::simplifyApplicableFnConstraint( type2 = getFixedTypeRecursive(type2, flags, /*wantRValue=*/true); auto desugar2 = type2->getDesugaredType(); + // If a type variable representing "function type" is a hole + // or it could be bound to some concrete type with a help of + // a fix, let's propagate holes to the "input" type. Doing so + // provides more information to upcoming argument and result matching. + if (shouldAttemptFixes()) { + if (auto *typeVar = type2->getAs()) { + auto *locator = typeVar->getImpl().getLocator(); + if (hasFixFor(locator)) { + recordAnyTypeVarAsPotentialHole(func1); + } + } + Type underlyingType = desugar2; + while (auto *MT = underlyingType->getAs()) { + underlyingType = MT->getInstanceType(); + } + underlyingType = + getFixedTypeRecursive(underlyingType, flags, /*wantRValue=*/true); + if (underlyingType->isPlaceholder()) { + recordAnyTypeVarAsPotentialHole(func1); + return SolutionKind::Solved; + } + } + TypeMatchOptions subflags = getDefaultDecompositionOptions(flags); SmallVector parts; @@ -12927,6 +12938,12 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyFixConstraint( case FixKind::RenameConflictingPatternVariables: { return recordFix(fix) ? SolutionKind::Error : SolutionKind::Solved; } + case FixKind::IgnoreInvalidASTNode: { + return recordFix(fix, 10) ? SolutionKind::Error : SolutionKind::Solved; + } + case FixKind::IgnoreInvalidNamedPattern: { + return recordFix(fix, 100) ? SolutionKind::Error : SolutionKind::Solved; + } case FixKind::ExplicitlyConstructRawRepresentable: { // Let's increase impact of this fix for binary operators because diff --git a/lib/Sema/ConstraintLocator.cpp b/lib/Sema/ConstraintLocator.cpp index de16895bf7fc9..b263cb36435ae 100644 --- a/lib/Sema/ConstraintLocator.cpp +++ b/lib/Sema/ConstraintLocator.cpp @@ -97,6 +97,7 @@ unsigned LocatorPathElt::getNewSummaryFlags() const { case ConstraintLocator::PackType: case ConstraintLocator::PackElement: case ConstraintLocator::PatternBindingElement: + case ConstraintLocator::NamedPatternDecl: return 0; case ConstraintLocator::FunctionArgument: @@ -441,6 +442,11 @@ void LocatorPathElt::dump(raw_ostream &out) const { << llvm::utostr(patternBindingElt.getIndex()); break; } + + case ConstraintLocator::NamedPatternDecl: { + out << "named pattern decl"; + break; + } } } @@ -592,6 +598,12 @@ void ConstraintLocator::dump(SourceManager *sm, raw_ostream &out) const { out << '@'; expr->getLoc().print(out, *sm); } + } else if (auto *pattern = anchor.dyn_cast()) { + out << Pattern::getKindName(pattern->getKind()) << "Pattern"; + if (sm) { + out << '@'; + pattern->getLoc().print(out, *sm); + } } for (auto elt : getPath()) { diff --git a/lib/Sema/ConstraintSystem.cpp b/lib/Sema/ConstraintSystem.cpp index 28d5271ce1583..7163374fa942a 100644 --- a/lib/Sema/ConstraintSystem.cpp +++ b/lib/Sema/ConstraintSystem.cpp @@ -5256,6 +5256,13 @@ void constraints::simplifyLocator(ASTNode &anchor, continue; } + case ConstraintLocator::NamedPatternDecl: { + auto pattern = cast(anchor.get()); + anchor = pattern->getDecl(); + path = path.slice(1); + break; + } + case ConstraintLocator::ImplicitConversion: break; diff --git a/test/ClangImporter/MixedSource/can_import_objc_idempotent.swift b/test/ClangImporter/MixedSource/can_import_objc_idempotent.swift index 60bdce2681174..9ba34ebaa4320 100644 --- a/test/ClangImporter/MixedSource/can_import_objc_idempotent.swift +++ b/test/ClangImporter/MixedSource/can_import_objc_idempotent.swift @@ -30,7 +30,7 @@ // expected-error@-1 {{cannot find 'CGRect' in scope}} let (r, s) = square.divided(atDistance: 50, from: .minXEdge) - // expected-error@-1 {{type of expression is ambiguous without more context}} + // expected-error@-1 {{cannot infer contextual base in reference to member 'minXEdge'}} #endif #if canImport(MixedWithHeader) diff --git a/test/Constraints/diagnostics.swift b/test/Constraints/diagnostics.swift index 7af4ccf0b6a6e..d2339c5257f74 100644 --- a/test/Constraints/diagnostics.swift +++ b/test/Constraints/diagnostics.swift @@ -1137,7 +1137,7 @@ func badTypes() { // rdar://34357545 func unresolvedTypeExistential() -> Bool { return (Int.self==_{}) - // expected-error@-1 {{type of expression is ambiguous without more context}} + // expected-error@-1 {{could not infer type for placeholder}} // expected-error@-2 {{type placeholder not allowed here}} } diff --git a/test/Constraints/overload.swift b/test/Constraints/overload.swift index 85ab17e5eb6e1..cf9de344f02e4 100644 --- a/test/Constraints/overload.swift +++ b/test/Constraints/overload.swift @@ -257,3 +257,10 @@ func rdar79672230() { var t: MyType = MyType() test(&t) // expected-error {{no exact matches in call to local function 'test'}} } + +// https://github.com/apple/swift/issues/60029 +for (key, values) in oldName { // expected-error{{cannot find 'oldName' in scope}} + for (idx, value) in values.enumerated() { + print(key, idx, value) + } +} diff --git a/test/IDE/complete_repl_identifier_prefix_1.swift b/test/IDE/complete_repl_identifier_prefix_1.swift index 6d2bb2527bdd9..e272ebd2fe589 100644 --- a/test/IDE/complete_repl_identifier_prefix_1.swift +++ b/test/IDE/complete_repl_identifier_prefix_1.swift @@ -1,6 +1,7 @@ // RUN: %target-swift-ide-test -repl-code-completion -source-filename %s | %FileCheck %s // CHECK: Begin completions +// CHECK-NEXT: .self: _ // CHECK-NEXT: {{^}}true: Bool{{$}} // CHECK-NEXT: End completions diff --git a/test/Parse/confusables.swift b/test/Parse/confusables.swift index b2969fd992053..9e5365537f407 100644 --- a/test/Parse/confusables.swift +++ b/test/Parse/confusables.swift @@ -11,6 +11,7 @@ let number⁚ Int // expected-note {{operator '⁚' (Two Dot Punctuation) looks // expected-error @+1 {{consecutive statements on a line must be separated by ';'}} 5 ‒ 5 // expected-note {{unicode character '‒' (Figure Dash) looks similar to '-' (Hyphen Minus); did you mean to use '-' (Hyphen Minus)?}} {{3-6=-}} +// expected-error @+3 {{cannot convert value of type '(Bool, _)' to expected condition type 'Bool'}} // expected-error @+2 {{cannot find 'ꝸꝸꝸ' in scope}} // expected-error @+1 {{expected ',' separator}} if (true ꝸꝸꝸ false) {} // expected-note {{identifier 'ꝸꝸꝸ' contains possibly confused characters; did you mean to use '&&&'?}} {{10-19=&&&}} diff --git a/test/Parse/invalid.swift b/test/Parse/invalid.swift index 58411d9a8ba50..45618ed3f1538 100644 --- a/test/Parse/invalid.swift +++ b/test/Parse/invalid.swift @@ -25,7 +25,10 @@ func runAction() {} // expected-note {{'runAction' declared here}} // rdar://16601779 func foo() { - runAction(SKAction.sequence() // expected-error {{cannot find 'SKAction' in scope; did you mean 'runAction'?}} {{13-21=runAction}} expected-error {{expected ',' separator}} {{32-32=,}} + // expected-error@+3 {{argument passed to call that takes no arguments}} + // expected-error@+2 {{cannot find 'SKAction' in scope; did you mean 'runAction'?}} {{13-21=runAction}} + // expected-error@+1 {{expected ',' separator}} {{32-32=,}} + runAction(SKAction.sequence() skview! // expected-error @-1 {{cannot find 'skview' in scope}} diff --git a/test/Parse/matching_patterns.swift b/test/Parse/matching_patterns.swift index a2a34c75825b6..c4a5f5ab56e9a 100644 --- a/test/Parse/matching_patterns.swift +++ b/test/Parse/matching_patterns.swift @@ -329,4 +329,4 @@ case (_?)?: break // expected-warning {{case is already handled by previous patt let (responseObject: Int?) = op1 // expected-error @-1 {{expected ',' separator}} {{25-25=,}} // expected-error @-2 {{expected pattern}} -// expected-error @-3 {{type of expression is ambiguous without more context}} +// expected-error @-3 {{cannot convert value of type 'Int?' to specified type '(responseObject: _)'}} diff --git a/test/Parse/subscripting.swift b/test/Parse/subscripting.swift index 9ce3156e75f6d..1da598efc6271 100644 --- a/test/Parse/subscripting.swift +++ b/test/Parse/subscripting.swift @@ -176,6 +176,7 @@ struct A6 { // expected-note@-2 {{did you mean}} get { return i + j // expected-error {{cannot find 'j' in scope}} + // expected-error@-1 {{cannot convert return expression of type 'Int' to return type '(Int) -> Int'}} } } } diff --git a/test/Parse/switch.swift b/test/Parse/switch.swift index 15af4dae176e9..8ea3ee43a8923 100644 --- a/test/Parse/switch.swift +++ b/test/Parse/switch.swift @@ -338,7 +338,7 @@ func f1(x: String, y: Whichever) { break case Whichever.alias: // expected-error {{expression pattern of type 'Whichever' cannot match values of type 'String'}} // expected-note@-1 {{overloads for '~=' exist}} - break + // expected-error@-2 {{'case' label in a 'switch' must have at least one executable statement}} default: break } diff --git a/test/Sema/editor_placeholders.swift b/test/Sema/editor_placeholders.swift index 30ffc6676effd..cf14d23b74fd2 100644 --- a/test/Sema/editor_placeholders.swift +++ b/test/Sema/editor_placeholders.swift @@ -1,8 +1,8 @@ // RUN: %target-typecheck-verify-swift -func foo(_ x: Int) -> Int {} // expected-note {{found this candidate}} -func foo(_ x: Float) -> Float {} // expected-note {{found this candidate}} -func foo(_ t: T) -> T {} // expected-note {{found this candidate}} +func foo(_ x: Int) -> Int {} +func foo(_ x: Float) -> Float {} +func foo(_ t: T) -> T {} var v = foo(<#T##x: Float##Float#>) // expected-error {{editor placeholder}} v = "" // expected-error {{cannot assign value of type 'String' to type 'Float'}} @@ -11,7 +11,7 @@ if (true) { <#code#> // expected-error {{editor placeholder}} } -foo(<#T##x: Undeclared##Undeclared#>) // expected-error {{editor placeholder}} expected-error {{cannot find type 'Undeclared' in scope}} expected-error {{ambiguous use of 'foo'}} +foo(<#T##x: Undeclared##Undeclared#>) // expected-error {{editor placeholder}} expected-error {{cannot find type 'Undeclared' in scope}} func f(_ n: Int) {} let a1 = <#T#> // expected-error{{editor placeholder in source file}} diff --git a/test/Sema/placeholder_type.swift b/test/Sema/placeholder_type.swift index 01e1727a4e01d..a9def5d4a49ef 100644 --- a/test/Sema/placeholder_type.swift +++ b/test/Sema/placeholder_type.swift @@ -110,13 +110,13 @@ extension Bar { } // FIXME: We should probably have better diagnostics for these situations--the user probably meant to use implicit member syntax -let _: Int = _() // expected-error {{type placeholder not allowed here}} expected-error {{type of expression is ambiguous without more context}} -let _: () -> Int = { _() } // expected-error 2 {{type placeholder not allowed here}} expected-error {{unable to infer closure type in the current context}} +let _: Int = _() // expected-error {{type placeholder not allowed here}} expected-error {{could not infer type for placeholder}} +let _: () -> Int = { _() } // expected-error 2 {{type placeholder not allowed here}} expected-error {{could not infer type for placeholder}} let _: Int = _.init() // expected-error {{type placeholder not allowed here}} expected-error {{could not infer type for placeholder}} let _: () -> Int = { _.init() } // expected-error 2 {{type placeholder not allowed here}} expected-error {{could not infer type for placeholder}} -func returnsInt() -> Int { _() } // expected-error {{type placeholder not allowed here}} expected-error {{type of expression is ambiguous without more context}} -func returnsIntClosure() -> () -> Int { { _() } } // expected-error 2 {{type placeholder not allowed here}} expected-error {{unable to infer closure type in the current context}} +func returnsInt() -> Int { _() } // expected-error {{type placeholder not allowed here}} expected-error {{could not infer type for placeholder}} +func returnsIntClosure() -> () -> Int { { _() } } // expected-error 2 {{type placeholder not allowed here}} expected-error {{could not infer type for placeholder}} func returnsInt2() -> Int { _.init() } // expected-error {{type placeholder not allowed here}} expected-error {{could not infer type for placeholder}} func returnsIntClosure2() -> () -> Int { { _.init() } } // expected-error 2 {{type placeholder not allowed here}} expected-error {{could not infer type for placeholder}} diff --git a/test/Serialization/Recovery/typedefs.swift b/test/Serialization/Recovery/typedefs.swift index 70fd6a4f076ad..02d7b27565e2f 100644 --- a/test/Serialization/Recovery/typedefs.swift +++ b/test/Serialization/Recovery/typedefs.swift @@ -56,6 +56,7 @@ let _ = wrapped // expected-error {{cannot find 'wrapped' in scope}} let _ = unwrapped // okay _ = usesWrapped(nil) // expected-error {{cannot find 'usesWrapped' in scope}} + // expected-error@-1 {{'nil' requires a contextual type}} _ = usesUnwrapped(nil) // expected-error {{'nil' is not compatible with expected argument type 'Int32'}} let _: WrappedAlias = nil // expected-error {{cannot find type 'WrappedAlias' in scope}} diff --git a/test/StringProcessing/Parse/forward-slash-regex.swift b/test/StringProcessing/Parse/forward-slash-regex.swift index 6cf273e3ba8ce..b7afb7efba52f 100644 --- a/test/StringProcessing/Parse/forward-slash-regex.swift +++ b/test/StringProcessing/Parse/forward-slash-regex.swift @@ -94,10 +94,11 @@ _ = /x/!.blah // expected-error@-2 {{value of type 'Regex' has no member 'blah'}} do { + // expected-error@+2 {{cannot find operator '/?' in scope}} + // expected-error@+1 {{'/' is not a prefix unary operator}} _ = /x /? .blah - // expected-error@-2 {{cannot find operator '/?' in scope}} - // expected-error@-3 {{'/' is not a prefix unary operator}} + // expected-error@-1 {{cannot infer contextual base in reference to member 'blah'}} } _ = /x/? // expected-error {{cannot use optional chaining on non-optional value of type 'Regex'}} .blah // expected-error {{value of type 'Regex' has no member 'blah'}} @@ -418,6 +419,7 @@ do { // expected-error@-1 {{'/' is not a prefix unary operator}} // expected-error@-2 {{consecutive statements on a line must be separated by ';'}} // expected-error@-3 {{expected expression}} + // expected-error@-4 {{cannot call value of non-function type '()'}} } do { _ = /[x])/ diff --git a/test/decl/func/operator.swift b/test/decl/func/operator.swift index 3a69179319cd4..14a1bc4574fdc 100644 --- a/test/decl/func/operator.swift +++ b/test/decl/func/operator.swift @@ -428,5 +428,5 @@ func testNonexistentPowerOperatorWithPowFunctionOutOfScope() { let x: Double = 3.0 let y: Double = 3.0 let z: Double = x**y // expected-error {{cannot find operator '**' in scope}} - let w: Double = a(x**2.0) // expected-error {{cannot find operator '**' in scope}} + let w: Double = a(x**2.0) // expected-error {{cannot find operator '**' in scope}} expected-error {{cannot convert value of type '()' to specified type 'Double'}} } diff --git a/test/decl/operator/power_operator_imported.swift b/test/decl/operator/power_operator_imported.swift index f9701c82893df..7ffd76f79164c 100644 --- a/test/decl/operator/power_operator_imported.swift +++ b/test/decl/operator/power_operator_imported.swift @@ -7,5 +7,5 @@ func testNonexistentPowerOperatorWithPowFunctionInScope() { let x: Double = 3.0 let y: Double = 3.0 let z: Double = x**y // expected-error {{no operator '**' is defined; did you mean 'pow(_:_:)'?}} - let w: Double = a(x**2.0) // expected-error {{no operator '**' is defined; did you mean 'pow(_:_:)'?}} + let w: Double = a(x**2.0) // expected-error {{no operator '**' is defined; did you mean 'pow(_:_:)'?}} expected-error {{cannot convert value of type '()' to specified type 'Double'}} } diff --git a/test/expr/closure/closures.swift b/test/expr/closure/closures.swift index b69917133ad13..9a751c0a559f9 100644 --- a/test/expr/closure/closures.swift +++ b/test/expr/closure/closures.swift @@ -475,9 +475,9 @@ var f = { (s: Undeclared) -> Int in 0 } // expected-error {{cannot find type 'Un // Swift compiler crashes when using closure, declared to return illegal type. func r21375863() { - var width = 0 // expected-warning {{variable 'width' was never mutated}} - var height = 0 // expected-warning {{variable 'height' was never mutated}} - var bufs: [[UInt8]] = (0..<4).map { _ -> [asdf] in // expected-error {{cannot find type 'asdf' in scope}} expected-warning {{variable 'bufs' was never used}} + var width = 0 + var height = 0 + var bufs: [[UInt8]] = (0..<4).map { _ -> [asdf] in // expected-error {{cannot find type 'asdf' in scope}} [UInt8](repeating: 0, count: width*height) } } diff --git a/test/expr/closure/multi_statement.swift b/test/expr/closure/multi_statement.swift index d2bd0feca5267..77a10631f883c 100644 --- a/test/expr/closure/multi_statement.swift +++ b/test/expr/closure/multi_statement.swift @@ -337,10 +337,9 @@ func test_unknown_refs_in_tilde_operator() { enum E { } - let _: (E) -> Void = { + let _: (E) -> Void = { // expected-error {{unable to infer closure type in the current context}} if case .test(unknown) = $0 { - // expected-error@-1 {{type 'E' has no member 'test'}} - // expected-error@-2 2 {{cannot find 'unknown' in scope}} + // expected-error@-1 2 {{cannot find 'unknown' in scope}} } } } diff --git a/test/expr/expressions.swift b/test/expr/expressions.swift index 77a3811388142..46e2b1d86278f 100644 --- a/test/expr/expressions.swift +++ b/test/expr/expressions.swift @@ -263,7 +263,6 @@ func test_lambda2() { { () -> protocol in // expected-error @-1 {{'protocol<...>' composition syntax has been removed and is not needed here}} {{11-24=Int}} // expected-error @-2 {{non-protocol, non-class type 'Int' cannot be used within a protocol-constrained type}} - // expected-warning @-3 {{result of call to closure returning 'Int' is unused}} return 1 }() } @@ -429,7 +428,7 @@ var fl_r: Float = 0x1.0fp // expected-error {{expected a digit in floating point var fl_s: Float = 0x1.0fp+ // expected-error {{expected a digit in floating point exponent}} var fl_t: Float = 0x1.p // expected-error {{value of type 'Int' has no member 'p'}} var fl_u: Float = 0x1.p2 // expected-error {{value of type 'Int' has no member 'p2'}} -var fl_v: Float = 0x1.p+ // expected-error {{'+' is not a postfix unary operator}} +var fl_v: Float = 0x1.p+ // expected-error {{'+' is not a postfix unary operator}} expected-error {{value of type 'Int' has no member 'p'}} var fl_w: Float = 0x1.p+2 // expected-error {{value of type 'Int' has no member 'p'}} var if1: Double = 1.0 + 4 // integer literal ok as double. diff --git a/test/type/protocol_composition.swift b/test/type/protocol_composition.swift index d2972e28c594e..853ccec2eb0d4 100644 --- a/test/type/protocol_composition.swift +++ b/test/type/protocol_composition.swift @@ -173,6 +173,10 @@ takesP1AndP2([Swift.AnyObject & P1 & P2]()) takesP1AndP2([AnyObject & protocol_composition.P1 & P2]()) takesP1AndP2([AnyObject & P1 & protocol_composition.P2]()) takesP1AndP2([DoesNotExist & P1 & P2]()) // expected-error {{cannot find 'DoesNotExist' in scope}} +// expected-error@-1 {{binary operator '&' cannot be applied to operands of type 'UInt8' and '(any P2).Type'}} +// expected-error@-2 {{binary operator '&' cannot be applied to operands of type 'UInt8' and '(any P1).Type'}} +// expected-note@-3 2 {{overloads for '&' exist with these partially matching parameter lists}} +// expected-error@-4 {{cannot call value of non-function type '[UInt8]'}} takesP1AndP2([Swift.DoesNotExist & P1 & P2]()) // expected-error {{module 'Swift' has no member named 'DoesNotExist'}} // expected-error@-1 {{binary operator '&' cannot be applied to operands of type 'UInt8' and '(any P2).Type'}} // expected-error@-2 {{binary operator '&' cannot be applied to operands of type 'UInt8' and '(any P1).Type'}} diff --git a/validation-test/compiler_crashers_2_fixed/0180-rdar45557325.swift b/validation-test/compiler_crashers_2_fixed/0180-rdar45557325.swift index 4058adff77613..5efd20c87b01e 100644 --- a/validation-test/compiler_crashers_2_fixed/0180-rdar45557325.swift +++ b/validation-test/compiler_crashers_2_fixed/0180-rdar45557325.swift @@ -8,5 +8,6 @@ class MyClass: NSObject { func f() { let url = URL(url) // expected-error{{use of local variable 'url' before its declaration}} // expected-note@-1 {{'url' declared here}} + // expected-error@-2 {{missing argument label 'string:' in call}} } }