Skip to content

Commit 987d4f0

Browse files
committed
Disallow inline given ... with ..
Only allow `inline given ... = ...` as the desugaring of `inline given ... with ..` is fundamentally incompatible with inline definitions.
1 parent 3e2b2cf commit 987d4f0

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3619,6 +3619,8 @@ object Parsers {
36193619
syntaxError(em"anonymous given cannot be abstract")
36203620
DefDef(name, joinParams(tparams, vparamss), parents.head, EmptyTree)
36213621
else
3622+
if mods.is(Inline) then
3623+
syntaxError(i"`inline given` cannot be implemented using a `with`")
36223624
val tparams1 = tparams.map(tparam => tparam.withMods(tparam.mods | PrivateLocal))
36233625
val vparamss1 = vparamss.map(_.map(vparam =>
36243626
vparam.withMods(vparam.mods &~ Param | ParamAccessor | Protected)))

tests/neg/i14177a.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import scala.compiletime.*
2+
3+
trait C[A]
4+
5+
inline given [Tup <: Tuple]: C[Tup] with // error
6+
val cs = summonAll[Tuple.Map[Tup, C]]

tests/neg/i14177b.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class T
2+
3+
inline given fail1: T with // error
4+
val cs = scala.compiletime.summonAll[EmptyTuple]
5+
inline given fail2[X]: T with // error
6+
val cs = scala.compiletime.summonAll[EmptyTuple]
7+
inline given fail3(using DummyImplicit): T with // error
8+
val cs = scala.compiletime.summonAll[EmptyTuple]
9+
10+
inline given ok1: T = new T:
11+
val cs = scala.compiletime.summonAll[EmptyTuple]
12+
inline given ok2[X]: T = new T:
13+
val cs = scala.compiletime.summonAll[EmptyTuple]
14+
inline given ok3(using DummyImplicit): T = new T:
15+
val cs = scala.compiletime.summonAll[EmptyTuple]

0 commit comments

Comments
 (0)