Skip to content

Backport "Disallow context function types as value-class parameters" to 3.3 LTS #362

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 28, 2025
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
7 changes: 4 additions & 3 deletions compiler/src/dotty/tools/dotc/config/ScalaSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand All @@ -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")
Expand Down
13 changes: 2 additions & 11 deletions compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand Down Expand Up @@ -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 {

Expand Down
2 changes: 2 additions & 0 deletions compiler/src/dotty/tools/dotc/typer/Checking.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
10 changes: 7 additions & 3 deletions tests/neg/i22552.check
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion tests/neg/i22552.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions tests/neg/i22752.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Inner(body: Int ?=> Int) extends AnyVal: // error
def rescue: Int ?=> Int = ???

class Inner2(body: Int => Int) extends AnyVal // ok
48 changes: 0 additions & 48 deletions tests/pos/i22643.scala

This file was deleted.

44 changes: 0 additions & 44 deletions tests/pos/i22645a.scala

This file was deleted.

12 changes: 0 additions & 12 deletions tests/pos/i22645b.scala

This file was deleted.

Loading