-
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 (#21733)
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. possible fix for #21213 --------- Co-authored-by: Dale Wijnand <[email protected]> Co-authored-by: Matt Bovel <[email protected]>
- Loading branch information
1 parent
c50a69f
commit 6d040c5
Showing
11 changed files
with
68 additions
and
8 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, as 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
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) |