Skip to content

Fix trait setter validity #12144

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions compiler/src/dotty/tools/dotc/transform/Mixin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import SymUtils._
import Symbols._
import SymDenotations._
import Types._
import Periods._
import Decorators._
import DenotTransformers._
import StdNames._
Expand Down Expand Up @@ -146,6 +147,7 @@ class Mixin extends MiniPhase with SymTransformer { thisPhase =>
// !decl.isClass avoids forcing nested traits, preventing cycles
if !decl.isClass && needsTraitSetter(decl) then
val setter = makeTraitSetter(decl.asTerm)
setter.validFor = thisPhase.validFor // validity of setter = next phase up to next transformer afterwards
decls1.enter(setter)
modified = true
if modified then
Expand Down
1 change: 1 addition & 0 deletions tests/pos/i12140/Test.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@main def Test = println(example.Trait.get)
14 changes: 14 additions & 0 deletions tests/pos/i12140/Trait.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Trait.scala
package example

import quoted._

trait Trait {
implicit val foo: Int = 23
}

object Trait {
inline def get: Trait = ${ getImpl }

def getImpl(using Quotes): Expr[Trait] = '{ new Trait {} }
}