Skip to content

Commit d0c27ff

Browse files
committed
Disallow by-name trait parameters
1 parent 93f24a0 commit d0c27ff

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

compiler/src/dotty/tools/dotc/ast/Desugar.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,11 @@ object desugar {
428428
}
429429
else originalTparams
430430

431+
if mods.is(Trait) then
432+
for vparams <- originalVparamss; vparam <- vparams do
433+
if vparam.tpt.isInstanceOf[ByNameTypeTree] then
434+
report.error(em"implementation restriction: traits cannot have by name parameters", vparam.srcPos)
435+
431436
// Annotations on class _type_ parameters are set on the derived parameters
432437
// but not on the constructor parameters. The reverse is true for
433438
// annotations on class _value_ parameters.

tests/neg/i9886.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
trait D(l: => Any): // error
2+
def f = l

0 commit comments

Comments
 (0)