-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Drop copied parent refinements before generating bytecode
Refinements are copied over from parents, because they might be needed for tracked members that should have more specific types in the child. These members are generated without an implementation and should not be used in runtime.
- Loading branch information
1 parent
b8c5ecb
commit 5a73a68
Showing
9 changed files
with
66 additions
and
6 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
35 changes: 35 additions & 0 deletions
35
compiler/src/dotty/tools/dotc/transform/DropParentRefinements.scala
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 @@ | ||
package dotty.tools.dotc.transform | ||
|
||
import dotty.tools.dotc.transform.MegaPhase.MiniPhase | ||
import dotty.tools.dotc.ast.tpd | ||
import dotty.tools.dotc.core.Contexts.Context | ||
import dotty.tools.dotc.core.DenotTransformers.IdentityDenotTransformer | ||
import dotty.tools.dotc.typer.Typer | ||
|
||
object DropParentRefinements: | ||
val name: String = "dropParentRefinements" | ||
val description: String = "drop parent refinements from a template" | ||
|
||
/** Drop parent refinements from a template. because they are generated without | ||
* an implementation. These refinements are unusally required for tracked | ||
* members with more specific types. | ||
*/ | ||
class DropParentRefinements extends MiniPhase with IdentityDenotTransformer: | ||
thisPhase => | ||
import tpd.* | ||
|
||
override def phaseName: String = DropParentRefinements.name | ||
|
||
override def description: String = DropParentRefinements.description | ||
|
||
override def runsAfterGroupsOf: Set[String] = Set(CountOuterAccesses.name) | ||
|
||
override def changesMembers: Boolean = true // the phase drops parent refinements | ||
|
||
override def transformTemplate(tree: tpd.Template)(using Context): tpd.Tree = | ||
val newBody = tree.body.filter(!_.hasAttachment(Typer.RefinementFromParent)) | ||
tree.body.foreach { member => | ||
if member.hasAttachment(Typer.RefinementFromParent) then | ||
member.symbol.dropAfter(thisPhase) | ||
} | ||
cpy.Template(tree)(body = newBody) |
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
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 @@ | ||
bar |
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,9 @@ | ||
import scala.language.experimental.modularity | ||
import scala.language.future | ||
|
||
sealed abstract class Foo(tracked val discriminator: String) | ||
class Bar extends Foo("bar") | ||
|
||
val bar: Foo = Bar() | ||
object Test extends App: | ||
println(bar.discriminator) |
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 @@ | ||
bar |
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,10 @@ | ||
import scala.language.experimental.modularity | ||
import scala.language.future | ||
|
||
enum Foo(tracked val discriminator: String): | ||
case Bar() extends Foo("bar") | ||
case Baz() extends Foo("baz") | ||
|
||
val bar: Foo = Foo.Bar() | ||
object Test extends App: | ||
println(bar.discriminator) |