Skip to content

Commit 7e4fd6a

Browse files
committed
Disallow erased inline definitions
The issue with the combination is that the `erased` semantics get lost as the code is inlined and the reference is removed. This implies that when we check for references to erased definitions we will not find it (exaclty as with inline alone).
1 parent db34814 commit 7e4fd6a

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,9 @@ object Checking {
541541
checkCombination(Abstract, Override)
542542
checkCombination(Private, Override)
543543
checkCombination(Lazy, Inline)
544+
// The issue with `erased inline` is that the erased semantics get lost
545+
// as the code is inlined and the reference is removed before the erased usage check.
546+
checkCombination(Erased, Inline)
544547
checkNoConflict(Lazy, ParamAccessor, s"parameter may not be `lazy`")
545548
}
546549

tests/pos-custom-args/erased/i7878.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ object Boom {
22
import scala.compiletime.*
33
trait Fail[A <: Int, B <: Int]
44

5-
erased transparent inline given fail[X <: Int, Y <: Int]: Fail[X, Y] = {
5+
transparent inline given fail[X <: Int, Y <: Int]: Fail[X, Y] = {
66
scala.compiletime.summonFrom {
77
case t: Fail[X, y] if constValue[y] < constValue[Y] => ???
88
}
@@ -12,4 +12,4 @@ object Boom {
1212
given ev1: Fail[a.type, 2] = null
1313

1414
summon[Fail[a.type, 3]]
15-
}
15+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import language.experimental.erasedDefinitions
2+
3+
erased inline def f: Unit = () // error: illegal combination of modifiers: `erased` and `inline` for: method f
4+
inline def g: Unit = ()

0 commit comments

Comments
 (0)