diff --git a/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala b/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala index 4ae5df316839..075ea2423f86 100644 --- a/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala +++ b/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala @@ -192,9 +192,10 @@ private sealed trait WarningSettings: ChoiceWithHelp("linted", "Enable -Wunused:imports,privates,locals,implicits"), ChoiceWithHelp( name = "strict-no-implicit-warn", - description = "Same as -Wunused:import, only for imports of explicit named members.\n" + - "NOTE : This overrides -Wunused:imports and NOT set by -Wunused:all" + description = """Same as -Wunused:imports, only for imports of explicit named members. + |NOTE : This overrides -Wunused:imports and NOT set by -Wunused:all""".stripMargin ), + ChoiceWithHelp("unsafe-warn-patvars", "Deprecated alias for `patvars`"), ), default = Nil ) @@ -219,7 +220,7 @@ private sealed trait WarningSettings: def params(using Context) = allOr("params") def privates(using Context) = allOr("privates") || allOr("linted") - def patvars(using Context) = allOr("patvars") + def patvars(using Context) = allOr("patvars") || isChoiceSet("unsafe-warn-patvars") def inlined(using Context) = isChoiceSet("inlined") def linted(using Context) = allOr("linted") diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index e92ef2f7ce69..47389fbce054 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -1677,9 +1677,8 @@ object Parsers { val start = in.offset val tparams = typeParamClause(ParamOwner.TypeParam) if in.token == TLARROW then - // Filter illegal context bounds and report syntax error atSpan(start, in.skipToken()): - LambdaTypeTree(tparams.mapConserve(stripContextBounds("type lambdas")), toplevelTyp()) + LambdaTypeTree(tparams, toplevelTyp()) else if in.token == ARROW || isPureArrow(nme.PUREARROW) then val arrowOffset = in.skipToken() val body = toplevelTyp() @@ -1700,13 +1699,6 @@ object Parsers { typeRest(infixType()) end typ - /** Removes context bounds from TypeDefs and returns a syntax error. */ - private def stripContextBounds(in: String)(tparam: TypeDef) = tparam match - case TypeDef(name, rhs: ContextBounds) => - syntaxError(em"context bounds are not allowed in $in", rhs.span) - TypeDef(name, rhs.bounds) - case other => other - private def makeKindProjectorTypeDef(name: TypeName): TypeDef = { val isVarianceAnnotated = name.startsWith("+") || name.startsWith("-") // We remove the variance marker from the name without passing along the specified variance at all @@ -3275,8 +3267,7 @@ object Parsers { * TypTypeParam ::= {Annotation} id [HkTypePamClause] TypeBounds * * HkTypeParamClause ::= ‘[’ HkTypeParam {‘,’ HkTypeParam} ‘]’ - * HkTypeParam ::= {Annotation} [‘+’ | ‘-’] - * (id | ‘_’) [HkTypeParamClause] TypeBounds + * HkTypeParam ::= {Annotation} [‘+’ | ‘-’] (id [HkTypePamClause] | ‘_’) TypeBounds */ def typeParamClause(paramOwner: ParamOwner): List[TypeDef] = inBracketsWithCommas { diff --git a/compiler/src/dotty/tools/dotc/typer/Checking.scala b/compiler/src/dotty/tools/dotc/typer/Checking.scala index 2757304f32e8..dda32fd380a7 100644 --- a/compiler/src/dotty/tools/dotc/typer/Checking.scala +++ b/compiler/src/dotty/tools/dotc/typer/Checking.scala @@ -755,6 +755,8 @@ object Checking { } clParamAccessors match { case param :: params => + if (defn.isContextFunctionType(param.info)) + report.error("value classes are not allowed for context function types", param.srcPos) if (param.is(Mutable)) report.error(ValueClassParameterMayNotBeAVar(clazz, param), param.srcPos) if (param.info.isInstanceOf[ExprType]) diff --git a/tests/neg/i22552.check b/tests/neg/i22552.check index 7a9b6c9800c7..910c8ad44c11 100644 --- a/tests/neg/i22552.check +++ b/tests/neg/i22552.check @@ -2,7 +2,11 @@ 3 | type A[X: TC] // error | ^ | ']' expected, but ':' found --- Error: tests/neg/i22552.scala:4:15 ---------------------------------------------------------------------------------- +-- [E040] Syntax Error: tests/neg/i22552.scala:4:13 -------------------------------------------------------------------- 4 | type C = [X: TC] =>> List[X] // error - | ^^ - | context bounds are not allowed in type lambdas + | ^ + | ']' expected, but ':' found +-- [E040] Syntax Error: tests/neg/i22552.scala:5:13 -------------------------------------------------------------------- +5 | type D = [X: TC] => () => List[X] // error + | ^ + | ']' expected, but ':' found diff --git a/tests/neg/i22552.scala b/tests/neg/i22552.scala index 5ac7840a3a96..d76c6ec2af8d 100644 --- a/tests/neg/i22552.scala +++ b/tests/neg/i22552.scala @@ -2,4 +2,4 @@ trait Foo: type TC[T] type A[X: TC] // error type C = [X: TC] =>> List[X] // error - type D = [X: TC] => () => List[X] // allowed context bound + type D = [X: TC] => () => List[X] // error diff --git a/tests/neg/i22752.scala b/tests/neg/i22752.scala new file mode 100644 index 000000000000..5c93b3ccbd68 --- /dev/null +++ b/tests/neg/i22752.scala @@ -0,0 +1,4 @@ +class Inner(body: Int ?=> Int) extends AnyVal: // error + def rescue: Int ?=> Int = ??? + +class Inner2(body: Int => Int) extends AnyVal // ok diff --git a/tests/pos/i22643.scala b/tests/pos/i22643.scala deleted file mode 100644 index 5b203c678740..000000000000 --- a/tests/pos/i22643.scala +++ /dev/null @@ -1,48 +0,0 @@ -import language.experimental.namedTuples - - - -object ExhibitB: - - trait JoinB[A <: Tuple, B <: Tuple]: - type NTB = NamedTuple.NamedTuple[Tuple.Concat[A, B], (String, Int)] - val ntB: NTB = ??? - - val joinB: JoinB[Tuple1["nameB"], Tuple1["ageB"]] = ??? - - joinB.ntB.nameB // works - - -object ExhibitC: - - type A = Tuple1["nameC"] - type B = Tuple1["ageC"] - - type NamesC = Tuple.Concat[A, B] - type NTC = NamedTuple.NamedTuple[NamesC, (String, Int)] - val ntC: NTC = ??? - - ntC.nameC // works - - -object ExhibitD: - - trait JoinD[A, B]: - type NamesD = (A, B) - type NTD = NamedTuple.NamedTuple[NamesD, (String, Int)] - val ntD: NTD = ??? - - val joinD: JoinD["nameD", "ageD"] = ??? - - joinD.ntD.nameD // works - -object ExhibitA: - - trait JoinA[A <: Tuple, B <: Tuple]: - type NamesA = Tuple.Concat[A, B] - type NTA = NamedTuple.NamedTuple[NamesA, (String, Int)] - val ntA: NTA = ??? - - val joinA: JoinA[Tuple1["nameA"], Tuple1["ageA"]] = ??? - - joinA.ntA.nameA // fixed diff --git a/tests/pos/i22645a.scala b/tests/pos/i22645a.scala deleted file mode 100644 index 3015d7dd161c..000000000000 --- a/tests/pos/i22645a.scala +++ /dev/null @@ -1,44 +0,0 @@ -import language.experimental.namedTuples -object ExhibitA: // fails - - class SelectableNT[N <: Tuple] extends Selectable: - def selectDynamic(name: String) = ??? - type Names = Tuple.Map[N, [X] =>> X] - type Fields = NamedTuple.NamedTuple[Names, (String, Int)] - - val x = new SelectableNT[("name", "age")] - x.name // fails - - -object ExhibitB: // works - - class SelectableNT[N <: Tuple] extends Selectable: - def selectDynamic(name: String) = ??? - type Fields = NamedTuple.NamedTuple[N, (String, Int)] - - val x = new SelectableNT[("name", "age")] - x.name - - -object ExhibitC: // works - - class SelectableNT[N <: Tuple] extends Selectable: - def selectDynamic(name: String) = ??? - type Fields = NamedTuple.NamedTuple[N, (String, Int)] - - type N = ("name", "age") - val x = new SelectableNT[N] - x.name - - -object ExhibitD: // works - - class SelectableNT[N <: Tuple] extends Selectable: - def selectDynamic(name: String) = ??? - type Fields = NamedTuple.NamedTuple[N, (String, Int)] - - type N = ("name", "age") - type Names = Tuple.Map[N, [X] =>> X] - val x = new SelectableNT[Names] - x.name - diff --git a/tests/pos/i22645b.scala b/tests/pos/i22645b.scala deleted file mode 100644 index acce89f25ee9..000000000000 --- a/tests/pos/i22645b.scala +++ /dev/null @@ -1,12 +0,0 @@ -import language.experimental.namedTuples -object ExhibitE: // works - - type N = ("name", "age") - type Names = Tuple.Map[N, [X] =>> X] - - class SelectableNT extends Selectable: - def selectDynamic(name: String) = ??? - type Fields = NamedTuple.NamedTuple[Names, (String, Int)] - - val x = new SelectableNT - x.name \ No newline at end of file