-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Parse
+_
and -_
in types as identifiers to support Scala 3.2 plac…
…eholder syntax This change allows `kind-projector` plugin to rewrite `+_` and `-_` tokens to type lambdas, in line with proposed syntax for Scala 3.2 in http://dotty.epfl.ch/docs/reference/changed-features/wildcards.html When used in conjunction with `-Xsource:3` this will let the user use `?` for wildcards and `_` for placeholders, letting the user cross-compile the same sources with Scala 3 with `-source:3.2` flag. This change is not source breaking since currently `+_` and `-_` fail to parse entirely, this change also does not allow the user to declare types with these names without backticks, they can only be used as part of a type tree. Gate `-_`/`+_` parsing behind `-Xsource:3` to guarantee minimal disruption to existing code
- Loading branch information
Showing
6 changed files
with
71 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
variant-placeholders-future.scala:4: error: `=', `>:', or `<:' expected | ||
type -_ = Int // error -_ not allowed as a type def name without backticks | ||
^ | ||
variant-placeholders-future.scala:5: error: `=', `>:', or `<:' expected | ||
type +_ = Int // error +_ not allowed as a type def name without backticks | ||
^ | ||
two errors found |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// scalac: -Xsource:3 | ||
// | ||
object Test { | ||
type -_ = Int // error -_ not allowed as a type def name without backticks | ||
type +_ = Int // error +_ not allowed as a type def name without backticks | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
variant-placeholders-nofuture.scala:5: error: ';' expected but '_' found. | ||
val fnMinusPlus1: -_ => +_ = (_: Int).toLong // error -_/+_ won't parse without -Xsource:3 | ||
^ | ||
variant-placeholders-nofuture.scala:6: error: ')' expected but '_' found. | ||
val fnMinusPlus2: (-_) => +_ = fnMinusPlus1 // error -_/+_ won't parse without -Xsource:3 | ||
^ | ||
two errors found |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
object Test { | ||
type `-_` = Int | ||
type `+_` = Long | ||
|
||
val fnMinusPlus1: -_ => +_ = (_: Int).toLong // error -_/+_ won't parse without -Xsource:3 | ||
val fnMinusPlus2: (-_) => +_ = fnMinusPlus1 // error -_/+_ won't parse without -Xsource:3 | ||
val fnMinusPlus3: -_ => (+_) = fnMinusPlus2 // error -_/+_ won't parse without -Xsource:3 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// scalac: -Xsource:3 | ||
// | ||
object Test { | ||
type `-_` = Int | ||
type `+_` = Long | ||
|
||
val fnMinusPlus1: -_ => +_ = (_: Int).toLong | ||
val fnMinusPlus2: (-_) => +_ = fnMinusPlus1 | ||
val fnMinusPlus3: -_ => (+_) = fnMinusPlus2 | ||
|
||
val fnTupMinusPlus2: (=> -_, -_) => +_ = (a, b) => ((a: Int) + (b: Int)).toLong | ||
def defMinusPlus2(byname: => -_, vararg: -_*): +_ = ((vararg.sum: Int) + (byname: -_)).toLong | ||
val infixMinusPlus2: -_ Either +_ = Right[-_, +_](1L) | ||
|
||
val optPlus: Option[+_] = Some[ + _ ](1L) // spaces allowed | ||
optPlus match { | ||
case opt: Option[ + _ ] => | ||
val opt1: + _ = opt.get | ||
val opt2: Long = opt1 | ||
} | ||
|
||
val optMinus: Option[-_] = Some[ - _ ](1) // spaces allowed | ||
optMinus match { | ||
case opt: Option[ - _ ] => | ||
val opt1: `-_` = opt.get | ||
val optErr: - _ = opt.get | ||
val opt2: Int = opt1 | ||
} | ||
|
||
locally { | ||
type `-_`[A] = A | ||
type `+_`[A] = Option[A] | ||
val optOpt: Option[ + _ [+_[-_[Int]]]] = Some(Some(Some(1))) | ||
} | ||
} |