Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9605 from 7mind/parse-variant-underscore-placehol…
…ders Parse `+_` and `-_` in types as identifiers to support Scala 3.2 placeholder syntax
- Loading branch information
Showing
6 changed files
with
71 additions
and
3 deletions.
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 | ||
^ | ||
2 errors |
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 | ||
^ | ||
2 errors |
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))) | ||
} | ||
} |