From 7e4fd6a08811738c31e6d4be77743b1e8eeeeee7 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Tue, 11 Jan 2022 15:44:21 +0100 Subject: [PATCH] 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). --- compiler/src/dotty/tools/dotc/typer/Checking.scala | 3 +++ tests/pos-custom-args/erased/i7878.scala | 4 ++-- tests/pos-custom-args/erasedInline.scala | 4 ++++ 3 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 tests/pos-custom-args/erasedInline.scala diff --git a/compiler/src/dotty/tools/dotc/typer/Checking.scala b/compiler/src/dotty/tools/dotc/typer/Checking.scala index f4ec37881d6c..85eba072f7a8 100644 --- a/compiler/src/dotty/tools/dotc/typer/Checking.scala +++ b/compiler/src/dotty/tools/dotc/typer/Checking.scala @@ -541,6 +541,9 @@ object Checking { checkCombination(Abstract, Override) checkCombination(Private, Override) checkCombination(Lazy, Inline) + // The issue with `erased inline` is that the erased semantics get lost + // as the code is inlined and the reference is removed before the erased usage check. + checkCombination(Erased, Inline) checkNoConflict(Lazy, ParamAccessor, s"parameter may not be `lazy`") } diff --git a/tests/pos-custom-args/erased/i7878.scala b/tests/pos-custom-args/erased/i7878.scala index 18005e81eab3..63b082d52ca0 100644 --- a/tests/pos-custom-args/erased/i7878.scala +++ b/tests/pos-custom-args/erased/i7878.scala @@ -2,7 +2,7 @@ object Boom { import scala.compiletime.* trait Fail[A <: Int, B <: Int] - erased transparent inline given fail[X <: Int, Y <: Int]: Fail[X, Y] = { + transparent inline given fail[X <: Int, Y <: Int]: Fail[X, Y] = { scala.compiletime.summonFrom { case t: Fail[X, y] if constValue[y] < constValue[Y] => ??? } @@ -12,4 +12,4 @@ object Boom { given ev1: Fail[a.type, 2] = null summon[Fail[a.type, 3]] -} \ No newline at end of file +} diff --git a/tests/pos-custom-args/erasedInline.scala b/tests/pos-custom-args/erasedInline.scala new file mode 100644 index 000000000000..6230dfb3dcb2 --- /dev/null +++ b/tests/pos-custom-args/erasedInline.scala @@ -0,0 +1,4 @@ +import language.experimental.erasedDefinitions + +erased inline def f: Unit = () // error: illegal combination of modifiers: `erased` and `inline` for: method f +inline def g: Unit = ()