-
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.
Differentiate Scala 2 and Scala 3 wildcard identifier names
This change names wildcards written with Scala 3 `?` syntax with `?$N` pattern instead of `_$N` used for Scala 2 wildcards There are two reasons for it: - To allow `kind-projector` to implement Scala 3 underscore syntax for type lambdas by transforming old-style underscores, but leaving Scala 3 underscores intact - To show a mildly more relevant error message, since a wildcard introduced by `?` will now also have a name with `?` in the error message
- Loading branch information
Showing
3 changed files
with
33 additions
and
11 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,11 @@ | ||
wildcards-future.scala:7: error: type mismatch; | ||
found : Map[_$1,_$2] where type _$2 >: Null, type _$1 <: AnyRef | ||
required: Map[String,String] | ||
underscores : Map[String, String] // error wildcard variables starting with `_` | ||
^ | ||
wildcards-future.scala:9: error: type mismatch; | ||
found : Map[?$1,?$2] where type ?$2 >: Null, type ?$1 <: AnyRef | ||
required: Map[String,String] | ||
qmarks : Map[String, String] // error – wildcard variables should start with `?` to differentiate from the old syntax | ||
^ | ||
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,11 @@ | ||
// scalac: -Xsource:3 | ||
// | ||
object Test { | ||
val underscores: Map[_ <: AnyRef, _ >: Null] = Map() | ||
val qmarks: Map[? <: AnyRef, ? >: Null] = Map() | ||
|
||
underscores : Map[String, String] // error wildcard variables starting with `_` | ||
|
||
qmarks : Map[String, String] // error – wildcard variables should start with `?` to differentiate from the old syntax | ||
// (and have a mildly more readable error...) | ||
} |