diff --git a/include/swift/AST/ASTBridging.h b/include/swift/AST/ASTBridging.h index 9a9e8544c1719..0e52d8156fc46 100644 --- a/include/swift/AST/ASTBridging.h +++ b/include/swift/AST/ASTBridging.h @@ -1938,6 +1938,12 @@ BridgedVarargTypeRepr_createParsed(BridgedASTContext cContext, BridgedTypeRepr base, BridgedSourceLoc cEllipsisLoc); +SWIFT_NAME( + "BridgedIntegerTypeRepr.createParsed(_:string:loc:minusLoc:)") +BridgedIntegerTypeRepr BridgedIntegerTypeRepr_createParsed( + BridgedASTContext cContext, BridgedStringRef cString, BridgedSourceLoc cLoc, + BridgedSourceLoc cMinusLoc); + SWIFT_NAME("BridgedTypeRepr.dump(self:)") void BridgedTypeRepr_dump(BridgedTypeRepr type); diff --git a/include/swift/Parse/Parser.h b/include/swift/Parse/Parser.h index c94dbde85b4ba..7c59e027d8cbe 100644 --- a/include/swift/Parse/Parser.h +++ b/include/swift/Parse/Parser.h @@ -1411,6 +1411,11 @@ class Parser { ParserResult parseTypeSimple( Diag<> MessageID, ParseTypeReason reason); + ParserResult parseTypeOrValue(); + ParserResult parseTypeOrValue(Diag<> MessageID, + ParseTypeReason reason = ParseTypeReason::Unspecified, + bool fromASTGen = false); + /// Parse layout constraint. LayoutConstraint parseLayoutConstraint(Identifier LayoutConstraintID); diff --git a/lib/AST/Bridging/TypeReprBridging.cpp b/lib/AST/Bridging/TypeReprBridging.cpp index b8ff8eee9199c..61eb2ddfa6217 100644 --- a/lib/AST/Bridging/TypeReprBridging.cpp +++ b/lib/AST/Bridging/TypeReprBridging.cpp @@ -298,3 +298,13 @@ BridgedExistentialTypeRepr_createParsed(BridgedASTContext cContext, return new (context) ExistentialTypeRepr(cAnyLoc.unbridged(), baseTy.unbridged()); } + +BridgedIntegerTypeRepr +BridgedIntegerTypeRepr_createParsed(BridgedASTContext cContext, + BridgedStringRef cString, + BridgedSourceLoc cLoc, + BridgedSourceLoc cMinusLoc) { + ASTContext &context = cContext.unbridged(); + return new (context) IntegerTypeRepr(cString.unbridged(), cLoc.unbridged(), + cMinusLoc.unbridged()); +} diff --git a/lib/ASTGen/Sources/ASTGen/Exprs.swift b/lib/ASTGen/Sources/ASTGen/Exprs.swift index 683cebae1c37e..cfa751cbef7cf 100644 --- a/lib/ASTGen/Sources/ASTGen/Exprs.swift +++ b/lib/ASTGen/Sources/ASTGen/Exprs.swift @@ -659,7 +659,7 @@ extension ASTGenVisitor { if let generics = node.genericArgumentClause { leftAngleLoc = self.generateSourceLoc(generics.leftAngle) genericArgs = generics.arguments.map { - self.generate(type: $0.argument) + self.generate(genericArgument: $0.argument) } rightAngleLoc = self.generateSourceLoc(generics.rightAngle) } else { @@ -760,7 +760,7 @@ extension ASTGenVisitor { let generics = node.genericArgumentClause let lAngleLoc = self.generateSourceLoc(generics.leftAngle) let genericArguments = generics.arguments.lazy.map { - self.generate(type: $0.argument) + self.generate(genericArgument: $0.argument) } let rAngleLoc = self.generateSourceLoc(generics.rightAngle) return .createParsed( diff --git a/lib/ASTGen/Sources/ASTGen/Generics.swift b/lib/ASTGen/Sources/ASTGen/Generics.swift index ab6e3449e42bb..81a3538286d2e 100644 --- a/lib/ASTGen/Sources/ASTGen/Generics.swift +++ b/lib/ASTGen/Sources/ASTGen/Generics.swift @@ -11,6 +11,9 @@ //===----------------------------------------------------------------------===// import ASTBridging + +@_spi(ExperimentalLanguageFeatures) +@_spi(RawSyntax) import SwiftSyntax extension ASTGenVisitor { @@ -72,8 +75,8 @@ extension ASTGenVisitor { return BridgedRequirementRepr( SeparatorLoc: self.generateSourceLoc(sameType.equal), Kind: .sameType, - FirstType: self.generate(type: sameType.leftType), - SecondType: self.generate(type: sameType.rightType) + FirstType: self.generate(sameTypeLeftType: sameType.leftType), + SecondType: self.generate(sameTypeRightType: sameType.rightType) ) case .layoutRequirement(_): // FIXME: Implement layout requirement translation. @@ -87,4 +90,71 @@ extension ASTGenVisitor { requirements: requirements.bridgedArray(in: self) ) } + + func generate(sameTypeLeftType node: SameTypeRequirementSyntax.LeftType) -> BridgedTypeRepr { + switch node { + case .type(let type): + return self.generate(type: type) + + case .expr(let expr): + return self.generateIntegerType(expr: expr).asTypeRepr + } + } + + func generate(sameTypeRightType node: SameTypeRequirementSyntax.RightType) -> BridgedTypeRepr { + switch node { + case .type(let type): + return self.generate(type: type) + + case .expr(let expr): + return self.generateIntegerType(expr: expr).asTypeRepr + } + } + + func generate(genericArgument node: GenericArgumentSyntax.Argument) -> BridgedTypeRepr { + switch node { + case .type(let type): + return self.generate(type: type) + + case .expr(let expr): + return self.generateIntegerType(expr: expr).asTypeRepr + } + } + + func generateIntegerType(expr node: ExprSyntax) -> BridgedIntegerTypeRepr { + var minusLoc = BridgedSourceLoc() + let literalExpr: IntegerLiteralExprSyntax + + // The only expressions generic argument types support right now are + // integer literals, '123', and prefix operators for negative integer + // literals, '-123'. + switch node.as(ExprSyntaxEnum.self) { + case .integerLiteralExpr(let node): + literalExpr = node + + case .prefixOperatorExpr(let node): + let op = node.operator + + guard op.text == "-" else { + fatalError("Unknown prefix operator for generic argument type") + } + + guard let node = node.expression.as(IntegerLiteralExprSyntax.self) else { + fatalError("Unknown expression kind for generic argument type") + } + + minusLoc = self.generateSourceLoc(op) + literalExpr = node + + default: + fatalError("Unknown expression kind for generic argument type") + } + + return .createParsed( + self.ctx, + string: self.copyAndStripUnderscores(text: literalExpr.literal.rawText), + loc: self.generateSourceLoc(literalExpr), + minusLoc: minusLoc + ) + } } diff --git a/lib/ASTGen/Sources/ASTGen/SourceFile.swift b/lib/ASTGen/Sources/ASTGen/SourceFile.swift index 7243f55fa5e4a..8684a51c85aa8 100644 --- a/lib/ASTGen/Sources/ASTGen/SourceFile.swift +++ b/lib/ASTGen/Sources/ASTGen/SourceFile.swift @@ -75,6 +75,7 @@ extension Parser.ExperimentalFeatures { mapFeature(.NonescapableTypes, to: .nonescapableTypes) mapFeature(.TrailingComma, to: .trailingComma) mapFeature(.CoroutineAccessors, to: .coroutineAccessors) + mapFeature(.ValueGenerics, to: .valueGenerics) } } diff --git a/lib/ASTGen/Sources/ASTGen/Types.swift b/lib/ASTGen/Sources/ASTGen/Types.swift index 45fd24f8caa6b..88ddbd0ab20f7 100644 --- a/lib/ASTGen/Sources/ASTGen/Types.swift +++ b/lib/ASTGen/Sources/ASTGen/Types.swift @@ -120,7 +120,7 @@ extension ASTGenVisitor { } let genericArguments = generics.arguments.lazy.map { - self.generate(type: $0.argument) + self.generate(genericArgument: $0.argument) } return BridgedUnqualifiedIdentTypeRepr.createParsed( @@ -140,7 +140,7 @@ extension ASTGenVisitor { let angleRange: BridgedSourceRange if let generics = node.genericArgumentClause { genericArguments = generics.arguments.lazy.map { - self.generate(type: $0.argument) + self.generate(genericArgument: $0.argument) }.bridgedArray(in: self) angleRange = self.generateSourceRange(start: generics.leftAngle, end: generics.rightAngle) diff --git a/lib/Macros/Sources/SwiftMacros/DistributedResolvableMacro.swift b/lib/Macros/Sources/SwiftMacros/DistributedResolvableMacro.swift index 8982ad965d121..858a4aa772642 100644 --- a/lib/Macros/Sources/SwiftMacros/DistributedResolvableMacro.swift +++ b/lib/Macros/Sources/SwiftMacros/DistributedResolvableMacro.swift @@ -9,6 +9,7 @@ // //===----------------------------------------------------------------------===// +@_spi(ExperimentalLanguageFeatures) import SwiftSyntax import SwiftSyntaxMacros import SwiftDiagnostics @@ -141,10 +142,25 @@ extension DistributedResolvableMacro { specificActorSystemRequirement = conformanceReq.rightType.trimmed isGenericStub = true - case .sameTypeRequirement(let sameTypeReq) - where sameTypeReq.leftType.isActorSystem: - specificActorSystemRequirement = sameTypeReq.rightType.trimmed - isGenericStub = false + case .sameTypeRequirement(let sameTypeReq): + switch sameTypeReq.leftType { + case .type(let type) where type.isActorSystem: + switch sameTypeReq.rightType.trimmed { + case .type(let rightType): + specificActorSystemRequirement = rightType + isGenericStub = false + + case .expr: + throw DiagnosticsError( + syntax: sameTypeReq.rightType, + message: "Expression type not supported for distributed actor", + id: .invalidGenericArgument + ) + } + + default: + continue + } default: continue @@ -265,6 +281,7 @@ struct DistributedResolvableMacroDiagnostic: DiagnosticMessage { enum ID: String { case invalidApplication = "invalid type" case missingInitializer = "missing initializer" + case invalidGenericArgument = "invalid generic argument" } var message: String diff --git a/lib/Macros/Sources/SwiftMacros/OptionSetMacro.swift b/lib/Macros/Sources/SwiftMacros/OptionSetMacro.swift index b9594b23191e2..62cc897d336d7 100644 --- a/lib/Macros/Sources/SwiftMacros/OptionSetMacro.swift +++ b/lib/Macros/Sources/SwiftMacros/OptionSetMacro.swift @@ -72,7 +72,7 @@ public struct OptionSetMacro { of attribute: AttributeSyntax, attachedTo decl: Decl, in context: Context - ) -> (StructDeclSyntax, EnumDeclSyntax, TypeSyntax)? { + ) -> (StructDeclSyntax, EnumDeclSyntax, GenericArgumentSyntax.Argument)? { // Determine the name of the options enum. let optionsEnumName: String if case let .argumentList(arguments) = attribute.arguments, diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp index 9d99226b24bdc..ff4a77d339647 100644 --- a/lib/Parse/ParseDecl.cpp +++ b/lib/Parse/ParseDecl.cpp @@ -3963,7 +3963,7 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes, return makeParserSuccess(); } - auto countType = parseType(diag::expected_type); + auto countType = parseTypeOrValue(diag::expected_type); if (countType.isNull()) { return makeParserSuccess(); } diff --git a/lib/Parse/ParseGeneric.cpp b/lib/Parse/ParseGeneric.cpp index ffd84b5ea50df..818e3bab7f79e 100644 --- a/lib/Parse/ParseGeneric.cpp +++ b/lib/Parse/ParseGeneric.cpp @@ -317,7 +317,9 @@ ParserStatus Parser::parseGenericWhereClause( // Parse the leading type. It doesn't necessarily have to be just a type // identifier if we're dealing with a same-type constraint. - ParserResult FirstType = parseType(); + // + // Note: This can be a value type, e.g. '123 == N' or 'N == 123'. + ParserResult FirstType = parseTypeOrValue(); if (FirstType.hasCodeCompletion()) { Status.setHasCodeCompletionAndIsError(); @@ -377,7 +379,9 @@ ParserStatus Parser::parseGenericWhereClause( SourceLoc EqualLoc = consumeToken(); // Parse the second type. - ParserResult SecondType = parseType(); + // + // Note: This can be a value type, e.g. '123 == N' or 'N == 123'. + ParserResult SecondType = parseTypeOrValue(); Status |= SecondType; if (SecondType.isNull()) SecondType = makeParserResult(ErrorTypeRepr::create(Context, PreviousLoc)); diff --git a/lib/Parse/ParseType.cpp b/lib/Parse/ParseType.cpp index df4bd5f4a996a..aba645461a011 100644 --- a/lib/Parse/ParseType.cpp +++ b/lib/Parse/ParseType.cpp @@ -175,12 +175,6 @@ ParserResult Parser::parseTypeSimple( tildeLoc = consumeToken(); } - // Eat any '-' preceding integer literals. - SourceLoc minusLoc; - if (Tok.isMinus() && peekToken().is(tok::integer_literal)) { - minusLoc = consumeToken(); - } - switch (Tok.getKind()) { case tok::kw_Self: case tok::identifier: @@ -237,12 +231,6 @@ ParserResult Parser::parseTypeSimple( } return makeParserCodeCompletionResult( ErrorTypeRepr::create(Context, consumeToken(tok::code_complete))); - case tok::integer_literal: { - auto text = copyAndStripUnderscores(Tok.getText()); - auto loc = consumeToken(tok::integer_literal); - ty = makeParserResult(new (Context) IntegerTypeRepr(text, loc, minusLoc)); - break; - } case tok::l_square: { ty = parseTypeCollection(); break; @@ -739,7 +727,8 @@ ParserStatus Parser::parseGenericArguments(SmallVectorImpl &Args, // variadic generic types. if (!startsWithGreater(Tok)) { while (true) { - ParserResult Ty = parseType(diag::expected_type); + // Note: This can be a value type, e.g. 'Vector<3, Int>'. + ParserResult Ty = parseTypeOrValue(diag::expected_type); if (Ty.isNull() || Ty.hasCodeCompletion()) { // Skip until we hit the '>'. RAngleLoc = skipUntilGreaterInTypeList(); @@ -1481,6 +1470,31 @@ Parser::parseTypeImplicitlyUnwrappedOptional(ParserResult base) { return makeParserResult(ParserStatus(base), TyR); } +ParserResult Parser::parseTypeOrValue() { + return parseTypeOrValue(diag::expected_type); +} + +ParserResult Parser::parseTypeOrValue(Diag<> MessageID, + ParseTypeReason reason, + bool fromASTGen) { + // Eat any '-' preceding integer literals. + SourceLoc minusLoc; + if (Tok.isMinus() && peekToken().is(tok::integer_literal)) { + minusLoc = consumeToken(); + } + + // Attempt to parse values first. Right now the only value that can be parsed + // as a type are integers. + if (Tok.is(tok::integer_literal)) { + auto text = copyAndStripUnderscores(Tok.getText()); + auto loc = consumeToken(tok::integer_literal); + return makeParserResult(new (Context) IntegerTypeRepr(text, loc, minusLoc)); + } + + // Otherwise, attempt to parse a regular type. + return parseType(MessageID, reason, fromASTGen); +} + //===----------------------------------------------------------------------===// // Speculative type list parsing //===----------------------------------------------------------------------===// diff --git a/lib/SIL/Parser/ParseSIL.cpp b/lib/SIL/Parser/ParseSIL.cpp index 5250f62414992..41e4b70790654 100644 --- a/lib/SIL/Parser/ParseSIL.cpp +++ b/lib/SIL/Parser/ParseSIL.cpp @@ -1067,6 +1067,42 @@ bool SILParser::parseASTType(CanType &result, return false; } +bool SILParser::parseASTTypeOrValue(CanType &result, + GenericSignature genericSig, + GenericParamList *genericParams, + bool forceContextualType) { + auto parsedType = P.parseTypeOrValue(); + if (parsedType.isNull()) return true; + + // If we weren't given a specific generic context to resolve the type + // within, use the contextual generic parameters and always produce + // a contextual type. Otherwise, produce a contextual type only if + // we were asked for one. + bool wantContextualType = forceContextualType; + if (!genericSig) { + genericSig = ContextGenericSig; + wantContextualType = true; + } + if (genericParams == nullptr) + genericParams = ContextGenericParams; + + bindSILGenericParams(parsedType.get()); + + auto resolvedType = performTypeResolution( + parsedType.get(), /*isSILType=*/false, genericSig, genericParams); + if (wantContextualType && genericSig) { + resolvedType = genericSig.getGenericEnvironment() + ->mapTypeIntoContext(resolvedType); + } + + if (resolvedType->hasError()) + return true; + + result = resolvedType->getCanonicalType(); + + return false; +} + void SILParser::bindSILGenericParams(TypeRepr *TyR) { // Resolve the generic environments for parsed generic function and box types. class HandleSILGenericParamsWalker : public ASTWalker { @@ -3122,7 +3158,7 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B, CanType paramType; if (parseSILType(Ty) || parseVerbatim("for") || - parseASTType(paramType)) + parseASTTypeOrValue(paramType)) return true; ResultVal = B.createTypeValue(InstLoc, Ty, paramType); diff --git a/lib/SIL/Parser/SILParser.h b/lib/SIL/Parser/SILParser.h index 9a6c90f089ce6..df1a75543b881 100644 --- a/lib/SIL/Parser/SILParser.h +++ b/lib/SIL/Parser/SILParser.h @@ -235,6 +235,11 @@ class SILParser { return false; } + bool parseASTTypeOrValue(CanType &result, + GenericSignature genericSig = GenericSignature(), + GenericParamList *genericParams = nullptr, + bool forceContextualType = false); + std::optional parseOptionalAttribute(ArrayRef expected) { // We parse here @ . diff --git a/test/ASTGen/decls.swift b/test/ASTGen/decls.swift index f6697ccc8d4e9..2d56973949363 100644 --- a/test/ASTGen/decls.swift +++ b/test/ASTGen/decls.swift @@ -291,3 +291,12 @@ struct ValueStruct {} func genericTest1(_: T) {} func genericTest2(_: repeat each T) {} func genericTest4(_: ValueStruct) {} + +func concreteValueTest1(_: ValueStruct<123>) {} +func concreteValueTest2(_: ValueStruct<-123>) {} + +extension ValueStruct where N == 123 {} +extension ValueStruct where 123 == N {} +extension ValueStruct where N == -123 {} +extension ValueStruct where -123 == N {} + diff --git a/test/Interpreter/value_generics.swift b/test/Interpreter/value_generics.swift index ae576deabe845..e6db8bbfe57eb 100644 --- a/test/Interpreter/value_generics.swift +++ b/test/Interpreter/value_generics.swift @@ -1,5 +1,4 @@ -// RUN: %target-run-simple-swift(-enable-experimental-feature ValueGenerics -Xfrontend -disable-availability-checking -Xfrontend -disable-experimental-parser-round-trip) | %FileCheck %s -// FIXME: Remove -disable-experimental-parser-round-trip after https://github.com/swiftlang/swift-syntax/pull/2859 is merged +// RUN: %target-run-simple-swift(-enable-experimental-feature ValueGenerics -Xfrontend -disable-availability-checking) | %FileCheck %s // UNSUPPORTED: use_os_stdlib // UNSUPPORTED: back_deployment_runtime diff --git a/test/Macros/Inputs/syntax_macro_definitions.swift b/test/Macros/Inputs/syntax_macro_definitions.swift index 81a336ee01381..f2fd8ad55685a 100644 --- a/test/Macros/Inputs/syntax_macro_definitions.swift +++ b/test/Macros/Inputs/syntax_macro_definitions.swift @@ -1,6 +1,6 @@ import SwiftDiagnostics import SwiftOperators -import SwiftSyntax +@_spi(ExperimentalLanguageFeatures) import SwiftSyntax import SwiftSyntaxBuilder @_spi(ExperimentalLanguageFeature) import SwiftSyntaxMacros @@ -946,12 +946,25 @@ public struct AddAsyncMacro: PeerMacro { let returnType = completionHandlerParameter.parameters.first?.type let isResultReturn = returnType?.children(viewMode: .all).first?.description == "Result" - let successReturnType = - if isResultReturn { - returnType!.as(IdentifierTypeSyntax.self)!.genericArgumentClause?.arguments.first!.argument - } else { - returnType + + let successReturnType: TypeSyntax? + + if isResultReturn { + let argument = returnType!.as(IdentifierTypeSyntax.self)!.genericArgumentClause?.arguments.first!.argument + + switch argument { + case .some(.type(let type)): + successReturnType = type + + case .some(.expr(_)): + fatalError("expression not available here") + + case .none: + successReturnType = nil } + } else { + successReturnType = returnType + } // Remove completionHandler and comma from the previous parameter var newParameterList = funcDecl.signature.parameterClause.parameters diff --git a/test/ModuleInterface/value_generics.swift b/test/ModuleInterface/value_generics.swift index c5cea60129df6..51784a09225b9 100644 --- a/test/ModuleInterface/value_generics.swift +++ b/test/ModuleInterface/value_generics.swift @@ -1,7 +1,6 @@ // RUN: %empty-directory(%t) -// RUN: %target-swift-emit-module-interface(%t.swiftinterface) %s -module-name ValueGeneric -enable-experimental-feature ValueGenerics -disable-availability-checking -disable-experimental-parser-round-trip -// RUN: %target-swift-typecheck-module-from-interface(%t.swiftinterface) -module-name ValueGeneric -disable-availability-checking -disable-experimental-parser-round-trip -// FIXME: Remove -disable-experimental-parser-round-trip after https://github.com/swiftlang/swift-syntax/pull/2859 is merged +// RUN: %target-swift-emit-module-interface(%t.swiftinterface) %s -module-name ValueGeneric -enable-experimental-feature ValueGenerics -disable-availability-checking +// RUN: %target-swift-typecheck-module-from-interface(%t.swiftinterface) -module-name ValueGeneric -disable-availability-checking // RUN: %FileCheck %s < %t.swiftinterface // REQUIRES: swift_feature_ValueGenerics diff --git a/test/Parse/integer_types.swift b/test/Parse/integer_types.swift index 3ac09e87669ff..8d4ec0f4be092 100644 --- a/test/Parse/integer_types.swift +++ b/test/Parse/integer_types.swift @@ -1,8 +1,12 @@ // RUN: %target-typecheck-verify-swift -let a: 123 // expected-error {{integer unexpectedly used in a type position}} +let a: 123 // expected-error {{consecutive statements on a line must be separated by ';'}} + // expected-error@-1 {{expected type}} + // expected-warning@-2 {{integer literal is unused}} -let b: -123 // expected-error {{integer unexpectedly used in a type position}} +let b: -123 // expected-error {{consecutive statements on a line must be separated by ';'}} + // expected-error@-1 {{expected type}} + // expected-warning@-2 {{integer literal is unused}} let c: -Int // expected-error {{expected type}} // expected-error@-1 {{consecutive statements on a line must be separated by ';'}} @@ -30,3 +34,19 @@ let f = Generic<-Int>.self // expected-error {{generic parameter 'T' could not b // expected-error@-1 {{missing whitespace between '<' and '-' operators}} // expected-error@-2 {{'>' is not a postfix unary operator}} // expected-note@-3 {{explicitly specify the generic arguments to fix this issue}} + +let g: 123.Type // expected-error {{consecutive statements on a line must be separated by ';'}} + // expected-error@-1 {{expected type}} + // expected-error@-2 {{value of type 'Int' has no member 'Type'}} + +let h: 123.Protocol // expected-error {{consecutive statements on a line must be separated by ';'}} + // expected-error@-1 {{expected type}} + // expected-error@-2 {{value of type 'Int' has no member 'Protocol'}} + +let i: 123? // expected-error {{consecutive statements on a line must be separated by ';'}} + // expected-error@-1 {{expected type}} + // expected-error@-2 {{cannot use optional chaining on non-optional value of type 'Int'}} + +let j: 123! // expected-error {{consecutive statements on a line must be separated by ';'}} + // expected-error@-1 {{expected type}} + // expected-error@-2 {{cannot force unwrap value of non-optional type 'Int'}} diff --git a/test/Sema/value_generics.swift b/test/Sema/value_generics.swift index 842c24a70f75f..44c17d5190e40 100644 --- a/test/Sema/value_generics.swift +++ b/test/Sema/value_generics.swift @@ -1,5 +1,4 @@ -// RUN: %target-typecheck-verify-swift -enable-experimental-feature ValueGenerics -enable-experimental-feature NonescapableTypes -disable-availability-checking -disable-experimental-parser-round-trip -// FIXME: Remove -disable-experimental-parser-round-trip after https://github.com/swiftlang/swift-syntax/pull/2859 is merged +// RUN: %target-typecheck-verify-swift -enable-experimental-feature ValueGenerics -enable-experimental-feature NonescapableTypes -disable-availability-checking // REQUIRES: swift_feature_NonescapableTypes // REQUIRES: swift_feature_ValueGenerics @@ -53,18 +52,21 @@ struct Generic {} struct GenericWithIntParam {} extension Generic where T == 123 {} // expected-error {{cannot constrain type parameter 'T' to be integer '123'}} -extension Generic where T == 123.Type {} // expected-error {{integer unexpectedly used in a type position}} +extension Generic where T == 123.Type {} // expected-error {{cannot constrain type parameter 'T' to be integer '123'}} + // expected-error@-1 {{expected '{' in extension}} +extension Generic where T == 123? {} // expected-error {{cannot constrain type parameter 'T' to be integer '123'}} + // expected-error@-1 {{expected '{' in extension}} func f(_: Generic<123>) {} // expected-error {{integer unexpectedly used in a type position}} func g(_: Generic) {} // expected-error {{cannot use value type 'N' for generic argument 'T'}} -func h(_: (Int, 123)) {} // expected-error {{integer unexpectedly used in a type position}} -func i(_: () -> 123) {} // expected-error {{integer unexpectedly used in a type position}} +func h(_: (Int, 123)) {} // expected-error {{expected type}} +func i(_: () -> 123) {} // expected-error {{expected type}} func j(_: (A<123>) -> ()) {} // OK -func k(_: some 123) {} // expected-error {{integer unexpectedly used in a type position}} +func k(_: some 123) {} // expected-error {{expected parameter type following ':'}} func l(_: GenericWithIntParam<123, Int>) {} // expected-error {{cannot pass type 'Int' as a value for generic value 'N'}} func m(_: GenericWithIntParam) {} // OK -typealias One = 1 // expected-error {{integer unexpectedly used in a type position}} +typealias One = 1 // expected-error {{expected type in type alias declaration}} struct B {} // expected-error {{'UInt8' is not a supported value type for 'N'}} diff --git a/test/Serialization/value_generics.swift b/test/Serialization/value_generics.swift index 0f08758a489e7..c26fcf016b573 100644 --- a/test/Serialization/value_generics.swift +++ b/test/Serialization/value_generics.swift @@ -1,6 +1,5 @@ // RUN: %empty-directory(%t) -// RUN: %target-swift-frontend %s -emit-module -enable-experimental-feature ValueGenerics -enable-experimental-feature RawLayout -disable-availability-checking -disable-experimental-parser-round-trip -parse-as-library -o %t -// FIXME: Remove -disable-experimental-parser-round-trip after https://github.com/swiftlang/swift-syntax/pull/2859 is merged +// RUN: %target-swift-frontend %s -emit-module -enable-experimental-feature ValueGenerics -enable-experimental-feature RawLayout -disable-availability-checking -parse-as-library -o %t // RUN: %target-sil-opt -enable-sil-verify-all %t/value_generics.swiftmodule -o - | %FileCheck %s // REQUIRES: swift_feature_RawLayout diff --git a/test/attr/attr_implements_bad_parse.swift b/test/attr/attr_implements_bad_parse.swift index 17f0deb0bfe34..82f7f990d1709 100644 --- a/test/attr/attr_implements_bad_parse.swift +++ b/test/attr/attr_implements_bad_parse.swift @@ -1,7 +1,7 @@ // RUN: %target-swift-frontend -parse -verify %s struct S0 { - @_implements(1, Foo) // OK. We can parse integers as types now, so this is fine. We will diagnose its incorrect usage during type checking. + @_implements(1, Foo) // expected-error {{expected type}} func f() { } } diff --git a/test/expr/postfix/init/unqualified.swift b/test/expr/postfix/init/unqualified.swift index 645bef69ec32b..bb8372378d2c2 100644 --- a/test/expr/postfix/init/unqualified.swift +++ b/test/expr/postfix/init/unqualified.swift @@ -62,7 +62,7 @@ class Theodosia: Aaron { // FIXME: We could optimistically parse this as an expression instead // expected-error@+2 {{initializers may only be declared within a type}} - // expected-error@+1 {{integer unexpectedly used in a type position}} + // expected-error@+1 {{expected parameter type following ':'}} init(z: 0) } @@ -98,7 +98,7 @@ struct AaronStruct { // FIXME: We could optimistically parse this as an expression instead // expected-error@+2 {{initializers may only be declared within a type}} - // expected-error@+1 {{integer unexpectedly used in a type position}} + // expected-error@+1 {{expected parameter type following ':'}} init(y: 1) }