forked from scala/scala3
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
scala#17135 shows that traits also need an outer accessor if they are in a toplevel method (or lazy val). Fixes scala#17135
- Loading branch information
Showing
2 changed files
with
59 additions
and
4 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,53 @@ | ||
package doobie | ||
|
||
// original example | ||
def someFunction(param: Int): Int = { | ||
sealed trait Foo { | ||
def asString: String = this match { | ||
case Foo.CaseC => "C" | ||
} | ||
} | ||
object Foo { | ||
// Having an object here crashes the compiler. | ||
object CaseC extends Foo | ||
} | ||
|
||
??? | ||
} | ||
|
||
// minimization | ||
def foo = | ||
class Bar { | ||
// Having an object here crashes the compiler. | ||
lazy val CaseC = | ||
class Baz extends Foo | ||
new Baz() | ||
} | ||
val Bar: Bar = new Bar() | ||
trait Foo { | ||
def asString = Bar.CaseC | ||
} | ||
|
||
// variant: outer is lazy val | ||
lazy val lazyfoo = | ||
class Bar { | ||
// Having an object here crashes the compiler. | ||
lazy val CaseC = | ||
class Baz extends Foo | ||
new Baz() | ||
} | ||
val Bar: Bar = new Bar() | ||
trait Foo { | ||
def asString = Bar.CaseC | ||
} | ||
|
||
// other example | ||
def bar = | ||
sealed trait GADT2[A] extends Product with Serializable | ||
|
||
object GADT2 { | ||
case class IsDir(path: String) extends GADT2[_root_.scala.Boolean] | ||
case class Exists(path: String) extends GADT2[_root_.scala.Boolean] | ||
case class ReadBytes(path: String) extends GADT2[_root_.scala.Array[_root_.scala.Byte]] | ||
case class CopyOver(src: Seq[_root_.scala.Byte], path: String) extends GADT2[Int] | ||
} |