Skip to content

Commit 0e10437

Browse files
committed
contextual error
1 parent fef7f53 commit 0e10437

File tree

8 files changed

+20
-8
lines changed

8 files changed

+20
-8
lines changed

lib/Sema/CSGen.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4907,9 +4907,14 @@ bool ConstraintSystem::generateConstraints(
49074907
return convertTypeLocator;
49084908
};
49094909

4910-
// Substitute type variables in for placeholder types.
4910+
if (convertType->hasError()) {
4911+
recordFix(
4912+
IgnoreInvalidASTNode::create(*this, convertTypeLocator));
4913+
}
4914+
4915+
// Substitute type variables in for placeholder and error types.
49114916
convertType = convertType.transformRec([&](Type type) -> std::optional<Type> {
4912-
if (type->is<PlaceholderType>()) {
4917+
if (isa<PlaceholderType, ErrorType>(type.getPointer())) {
49134918
return Type(createTypeVariable(getLocator(type),
49144919
TVO_CanBindToNoEscape |
49154920
TVO_PrefersSubtypeBinding |

lib/Sema/TypeCheckStmt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1075,7 +1075,7 @@ class StmtChecker : public StmtVisitor<StmtChecker, Stmt*> {
10751075
assert(TheFunc && "Should have bailed from pre-check if this is None");
10761076

10771077
Type ResultTy = TheFunc->getBodyResultType();
1078-
if (!ResultTy || ResultTy->hasError())
1078+
if (!ResultTy)
10791079
return nullptr;
10801080

10811081
if (!RS->hasResult()) {

test/AutoDiff/Sema/differentiable_attr_type_checking.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ class Super: Differentiable {
643643
// "covariant 'Self' can only appear at the top level of method result type".
644644
// expected-error @+1 2 {{'TangentVector' is not a member type of type 'Self'}}
645645
func vjpDynamicSelfResult() -> (Self, (Self.TangentVector) -> Self.TangentVector) {
646-
return (self, { $0 })
646+
return (self, { $0 }) // expected-error {{cannot infer type of closure parameter '$0' without a type annotation}}
647647
}
648648
}
649649

test/Parse/subscripting.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ struct A2 {
142142
subscript (i : Int) -> // expected-error{{expected subscripting element type}}
143143
{
144144
get {
145-
return stored
145+
return stored // expected-error {{cannot find 'stored' in scope}}
146146
}
147147
set {
148148
stored = newValue // expected-error{{cannot find 'stored' in scope}}

test/SPI/implicit_spi_import.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,9 @@ import Lib
9595
public func useImplicit() -> _Klass { return _Klass() } // expected-error{{cannot use class '_Klass' here; it is an SPI imported from 'Lib'}}
9696

9797
@_spi(core)
98-
public func useSPICore() -> CoreStruct { return CoreStruct() } // expected-error{{cannot find type 'CoreStruct' in scope}}
98+
public func useSPICore() -> CoreStruct { return CoreStruct() }
99+
// expected-error@-1 {{cannot find type 'CoreStruct' in scope}}
100+
// expected-error@-2 {{cannot find 'CoreStruct' in scope}}
99101

100102
public func useMain() -> APIProtocol? { return nil }
101103

test/Sema/placeholder_type.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ struct Just<Output>: Publisher {
205205
struct SetFailureType<Output, Failure>: Publisher {}
206206

207207
extension Publisher {
208-
func setFailureType<T>(to: T.Type) -> SetFailureType<Output, T> { // expected-note 2 {{in call to function 'setFailureType(to:)'}}
208+
func setFailureType<T>(to: T.Type) -> SetFailureType<Output, T> { // expected-note 3 {{in call to function 'setFailureType(to:)'}}
209209
return .init()
210210
}
211211
}
@@ -257,6 +257,8 @@ func mismatchedReturnTypes() -> _ { // expected-error {{type placeholder may not
257257
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
258258
func opaque() -> some _ { // expected-error {{type placeholder not allowed here}}
259259
return Just<Int>().setFailureType(to: _.self)
260+
// expected-error@-1 {{type placeholder not allowed here}}
261+
// expected-error@-2 {{generic parameter 'T' could not be inferred}}
260262
}
261263

262264
enum EnumWithPlaceholders {

test/decl/protocol/protocols.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,12 +423,14 @@ protocol P1 {
423423
protocol P2 {
424424
}
425425

426-
struct X3<T : P1> where T.Assoc : P2 {}
426+
struct X3<T : P1> where T.Assoc : P2 {} // expected-note {{'T' declared as parameter to type 'X3'}}
427427

428428
struct X4 : P1 {
429429
// expected-error@-1 {{type 'X4' does not conform to protocol 'P1'}}
430430
// expected-note@-2 {{add stubs for conformance}}
431431
func getX1() -> X3<X4> { return X3() }
432+
// expected-error@-1 {{generic parameter 'T' could not be inferred}}
433+
// expected-note@-2 {{explicitly specify the generic arguments to fix this issue}}
432434
}
433435

434436
protocol ShouldntCrash {

validation-test/compiler_crashers_2_fixed/issue-52031.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@ extension S: P where N: P {
1616
// expected-error@-3 {{'A' is not a member type of type 'X'}}
1717
// expected-error@-4 {{'A' is not a member type of type 'X'}}
1818
return S<X.A>()
19+
// expected-error@-1 {{'A' is not a member type of type 'X'}}
1920
}
2021
}

0 commit comments

Comments
 (0)