Skip to content

Commit 08eea86

Browse files
committed
Specialize types of inline values
Specialize types of ibline values even if a wider type was gven in an inherited definition. This generalizes a previous scheme for final vals.
1 parent f0cdff5 commit 08eea86

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

compiler/src/dotty/tools/dotc/typer/Namer.scala

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,15 +1323,8 @@ class Namer { typer: Typer =>
13231323
def cookedRhsType = deskolemize(dealiasIfUnit(widenRhs(rhsType)))
13241324
def lhsType = fullyDefinedType(cookedRhsType, "right-hand side", mdef.span)
13251325
//if (sym.name.toString == "y") println(i"rhs = $rhsType, cooked = $cookedRhsType")
1326-
if (inherited.exists) {
1327-
if (sym.is(Final, butNot = Method)) {
1328-
val tp = lhsType
1329-
if (tp.isInstanceOf[ConstantType])
1330-
tp // keep constant types that fill in for a non-constant (to be revised when inline has landed).
1331-
else inherited
1332-
}
1333-
else inherited
1334-
}
1326+
if (inherited.exists)
1327+
if (isInlineVal) lhsType else inherited
13351328
else {
13361329
if (sym.is(Implicit))
13371330
mdef match {

tests/pos/givenFallback.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
trait TC[T] { def x: Int; def y: Int = 0 }
2+
3+
given [T] as TC[T] {
4+
inline val x = 1
5+
}
6+
7+
given as TC[Int] {
8+
inline val x = 2
9+
inline override val y = 3
10+
}
11+
12+
object Test extends App {
13+
val z: 2 = the[TC[Int]].x
14+
val _: 3 = the[TC[Int]].y
15+
}

0 commit comments

Comments
 (0)