File tree Expand file tree Collapse file tree 2 files changed +15
-6
lines changed
compiler/src/dotty/tools/dotc/typer Expand file tree Collapse file tree 2 files changed +15
-6
lines changed Original file line number Diff line number Diff line change @@ -55,7 +55,7 @@ trait Deriving { this: Typer =>
55
55
// derived instance at the summoning site.
56
56
57
57
val (lazyOrMethod, rhsType) = info match {
58
- case ExprType (rhsType) => (Lazy , rhsType)
58
+ case ExprType (rhsType) => (Final | Lazy | StableRealizable , rhsType)
59
59
case _ => (Method , info)
60
60
}
61
61
@@ -177,7 +177,7 @@ trait Deriving { this: Typer =>
177
177
typed(rhs, resultType)
178
178
}
179
179
180
- def typeclassValInstance (sym : Symbol ): Tree = {
180
+ def typeclassValInstance (sym : Symbol )( implicit ctx : Context ) : Tree = {
181
181
val rhsType = sym.info
182
182
val module = untpd.ref(companionRef(rhsType)).withSpan(sym.span)
183
183
val rhs = untpd.Select (module, nme.derived)
@@ -193,11 +193,12 @@ trait Deriving { this: Typer =>
193
193
}
194
194
195
195
def syntheticDef (sym : Symbol ): Tree = {
196
+ val localCtx = ctx.fresh.setOwner(sym).setNewScope
196
197
sym.info match {
197
198
case _ : MethodicType =>
198
- tpd.polyDefDef(sym.asTerm, typeclassDefInstance(sym)(ctx.fresh.setOwner(sym).setNewScope ))
199
+ tpd.polyDefDef(sym.asTerm, typeclassDefInstance(sym)(localCtx ))
199
200
case _ =>
200
- typeclassValInstance(sym)
201
+ typeclassValInstance(sym)(localCtx)
201
202
}
202
203
}
203
204
Original file line number Diff line number Diff line change 1
1
import scala .deriving ._
2
2
3
3
object Test extends App {
4
- case class Mono (i : Int ) derives Foo , Bar
5
- case class Poly [T ](t : T ) derives Foo , Bar , Baz
4
+ case class Mono (i : Int ) derives Foo , Bar , Inline
5
+ case class Poly [T ](t : T ) derives Foo , Bar , Baz , Inline
6
6
7
7
trait Quux [T ]
8
8
object Quux {
@@ -26,13 +26,21 @@ object Test extends App {
26
26
def derived [F [_]] given (m : Mirror { type MirroredType = F }): Baz [F ] = new Baz [F ] {}
27
27
}
28
28
29
+ trait Inline [T ]
30
+ object Inline {
31
+ given as Inline [Int ] {}
32
+ inline def derived [T ] given (m : Mirror .Of [T ]): Inline [T ] = new Inline [T ] {}
33
+ }
34
+
29
35
// Unfortunately these tests doesn't distinguish a lazy val
30
36
// from a cached def
31
37
assert(the[Foo [Mono ]] eq the[Foo [Mono ]])
32
38
assert(the[Bar [Mono ]] eq the[Bar [Mono ]])
33
39
assert(the[Baz [Poly ]] eq the[Baz [Poly ]])
40
+ assert(the[Inline [Mono ]] eq the[Inline [Mono ]])
34
41
35
42
// These have term arguments so should be distinct
36
43
assert(the[Foo [Poly [Int ]]] ne the[Foo [Poly [Int ]]])
37
44
assert(the[Bar [Poly [Int ]]] ne the[Bar [Poly [Int ]]])
45
+ assert(the[Inline [Poly [Int ]]] ne the[Inline [Poly [Int ]]])
38
46
}
You can’t perform that action at this time.
0 commit comments