Skip to content
Merged
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
6 changes: 4 additions & 2 deletions include/swift/AST/DiagnosticsSema.def
Original file line number Diff line number Diff line change
Expand Up @@ -923,12 +923,14 @@ NOTE(c_function_pointer_captures_here,none,
//------------------------------------------------------------------------------

ERROR(var_type_not_materializable,none,
"type %0 of variable is not materializable", (Type))
"variable has type %0 which includes nested inout parameters",
(Type))
ERROR(param_type_non_materializable_tuple,none,
"named parameter has type %0 which includes nested inout parameters",
(Type))
ERROR(enum_element_not_materializable,none,
"type of enum case is not materializable", ())
"enum case has type %0 which includes nested inout parameters",
(Type))

ERROR(missing_initializer_def,PointsToFirstBadToken,
"initializer requires a body", ())
Expand Down
7 changes: 5 additions & 2 deletions lib/Sema/TypeCheckAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1831,6 +1831,9 @@ void TypeChecker::checkDeclAttributes(Decl *D) {
}

void TypeChecker::checkTypeModifyingDeclAttributes(VarDecl *var) {
if (!var->hasType())
return;

if (auto *attr = var->getAttrs().getAttribute<OwnershipAttr>())
checkOwnershipAttr(var, attr);
if (auto *attr = var->getAttrs().getAttribute<AutoClosureAttr>()) {
Expand Down Expand Up @@ -1858,7 +1861,7 @@ void TypeChecker::checkTypeModifyingDeclAttributes(VarDecl *var) {
void TypeChecker::checkAutoClosureAttr(ParamDecl *PD, AutoClosureAttr *attr) {
// The paramdecl should have function type, and we restrict it to functions
// taking ().
auto *FTy = PD->getType()->getAs<FunctionType>();
auto *FTy = PD->getInterfaceType()->getAs<FunctionType>();
if (!FTy) {
diagnose(attr->getLocation(), diag::autoclosure_function_type);
attr->setInvalid();
Expand Down Expand Up @@ -1912,7 +1915,7 @@ void TypeChecker::checkAutoClosureAttr(ParamDecl *PD, AutoClosureAttr *attr) {

void TypeChecker::checkNoEscapeAttr(ParamDecl *PD, NoEscapeAttr *attr) {
// The paramdecl should have function type.
auto *FTy = PD->getType()->getAs<FunctionType>();
auto *FTy = PD->getInterfaceType()->getAs<FunctionType>();
if (FTy == nullptr) {
diagnose(attr->getLocation(), diag::noescape_function_type);
attr->setInvalid();
Expand Down
3 changes: 2 additions & 1 deletion lib/Sema/TypeCheckDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6265,7 +6265,8 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
// Require the carried type to be materializable.
if (EED->getArgumentType() &&
!EED->getArgumentType()->isMaterializable()) {
TC.diagnose(EED->getLoc(), diag::enum_element_not_materializable);
TC.diagnose(EED->getLoc(), diag::enum_element_not_materializable,
EED->getArgumentType());
EED->setInterfaceType(ErrorType::get(TC.Context));
EED->setInvalid();
}
Expand Down
4 changes: 2 additions & 2 deletions test/Constraints/lvalues.swift
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,9 @@ func testInOut(_ arg: inout Int) {
}

// Don't infer inout types.
var ir = &i // expected-error{{type 'inout Int' of variable is not materializable}} \
var ir = &i // expected-error{{variable has type 'inout Int' which includes nested inout parameters}} \
// expected-error{{'&' can only appear immediately in a call argument list}}
var ir2 = ((&i)) // expected-error{{type 'inout Int' of variable is not materializable}} \
var ir2 = ((&i)) // expected-error{{variable has type 'inout Int' which includes nested inout parameters}} \
// expected-error{{'&' can only appear immediately in a call argument list}}

// <rdar://problem/17133089>
Expand Down
3 changes: 3 additions & 0 deletions test/attr/attr_noescape.swift
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,11 @@ enum r19997577Type {
// type attribute and decl attribute
func noescapeD(@noescape f: @escaping () -> Bool) {} // expected-error {{@noescape is now an attribute on a parameter type, instead of on the parameter itself}} {{16-25=}} {{29-29=@noescape }}
func noescapeT(f: @noescape () -> Bool) {} // expected-warning{{@noescape is the default and is deprecated}} {{19-29=}}
func noescapeG<T>(@noescape f: () -> T) {} // expected-error{{@noescape is now an attribute on a parameter type, instead of on the parameter itself}}

func autoclosureD(@autoclosure f: () -> Bool) {} // expected-error {{@autoclosure is now an attribute on a parameter type, instead of on the parameter itself}} {{19-31=}} {{35-35=@autoclosure }}
func autoclosureT(f: @autoclosure () -> Bool) {} // ok
func autoclosureG<T>(@autoclosure f: () -> T) {} // expected-error{{@autoclosure is now an attribute on a parameter type, instead of on the parameter itself}}

func noescapeD_noescapeT(@noescape f: @noescape () -> Bool) {} // expected-error {{@noescape is now an attribute on a parameter type, instead of on the parameter itself}}
// expected-warning@-1{{@noescape is the default and is deprecated}} {{39-49=}}
Expand Down
6 changes: 6 additions & 0 deletions test/decl/enum/enumtest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -311,3 +311,9 @@ enum SyntheticMember { // expected-note {{did you mean the implicitly-synthesize
case Foo
}
print(SyntheticMember.Foo.hasValue) // expected-error {{value of type 'SyntheticMember' has no member 'hasValue'}}

// Non-materializable argument type
enum Lens<T> {
case foo(inout T) // expected-error {{'inout' may only be used on parameters}}
case bar(inout T, Int) // expected-error {{'inout' may only be used on parameters}}
}
6 changes: 3 additions & 3 deletions test/expr/expressions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -523,9 +523,9 @@ func testInOut(_ arg: inout Int) {
takesExplicitInt(&x)
takesInt(&x) // expected-error{{'&' used with non-inout argument of type 'Int'}}
var y = &x // expected-error{{'&' can only appear immediately in a call argument list}} \
// expected-error {{type 'inout Int' of variable is not materializable}}
// expected-error {{variable has type 'inout Int' which includes nested inout parameters}}
var z = &arg // expected-error{{'&' can only appear immediately in a call argument list}} \
// expected-error {{type 'inout Int' of variable is not materializable}}
// expected-error {{variable has type 'inout Int' which includes nested inout parameters}}

takesExplicitInt(5) // expected-error {{cannot pass immutable value as inout argument: literals are not mutable}}
}
Expand Down Expand Up @@ -810,7 +810,7 @@ func inoutTests(_ arr: inout Int) {
(true ? &x : &y) // expected-error 2 {{'&' can only appear immediately in a call argument list}}
// expected-warning @-1 {{expression of type 'inout Int' is unused}}
let a = (true ? &x : &y) // expected-error 2 {{'&' can only appear immediately in a call argument list}}
// expected-error @-1 {{type 'inout Int' of variable is not materializable}}
// expected-error @-1 {{variable has type 'inout Int' which includes nested inout parameters}}

inoutTests(true ? &x : &y); // expected-error 2 {{'&' can only appear immediately in a call argument list}}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// RUN: %target-swift-frontend %s -emit-ir

enum Term<S> where S: Sequence, S.Iterator.Element == Term {
case Cons(head: String, tail: S)
}

func produce<S>(s: S) -> Term<S> {
return .Cons(head: "hi", tail: s)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors

// RUN: not --crash %target-swift-frontend %s -emit-ir
// RUN: not %target-swift-frontend %s -emit-ir
// REQUIRES: asserts
protocol b{func a(@autoclosure())