-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Disallow naming the root package, except for selections (#18187)
References #18020, didn't actually fix that, because it addressed aspects of using `_root_` in definitions. Adding more details to that ticket. Fixes #17757 Fixes #18050 Includes the code in scala/bug#12508
- Loading branch information
Showing
3 changed files
with
86 additions
and
17 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
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,62 @@ | ||
import _root_.scala.StringContext // ok | ||
|
||
class Test : | ||
val Foo = 1 | ||
def foo0: Unit = | ||
val x = new _root_.scala.StringContext() // ok | ||
val y: Option[_root_.scala.Serializable] = None // ok | ||
val z: _root_.scala.None.type = None | ||
val w = _root_.scala.None | ||
val (_root_, other) = (1, 2) // error | ||
val (Test.this.Foo, 1) = ??? | ||
??? match | ||
case (Test.this.Foo, 1) => () | ||
|
||
def foo3 = | ||
val _root_ = "abc" // error | ||
|
||
def foo1: Unit = | ||
val _root_: String = "abc" // error // error | ||
// _root_: is, technically, a legal name | ||
// so then it tries to construct the infix op pattern | ||
// "_root_ String .." and then throws in a null when it fails | ||
// to find an argument | ||
// then Typer rejects "String" as an infix extractor (like ::) | ||
// which is the second error | ||
|
||
def foo2: Unit = // error | ||
val _root_ : String = "abc" // error | ||
|
||
// i17757 | ||
def fooVal: Unit = | ||
val _root_ = "abc" // error | ||
println(_root_.length) // error | ||
println(_root_) // error | ||
|
||
def barVal: Unit = | ||
_root_ // error | ||
_root_.scala // error | ||
println(_root_) // error | ||
println(_root_.scala) // error | ||
|
||
// i18050 | ||
package p { | ||
package _root_ { // error | ||
object X // error | ||
} | ||
} | ||
|
||
// scala/bug#12508 | ||
package _root_ { // error | ||
class C { | ||
val _root_ = 42 // error | ||
} | ||
} | ||
package _root_.p { // error | ||
class C | ||
} | ||
|
||
// from ScalaPB | ||
def fromScalaPb(x: Option[String]) = x match | ||
case _root_.scala.Some(s) => s | ||
case _ => "" |