From d0c27ff8f3eef58a18bd173d0bce47a0ccc9865f Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Sun, 15 Nov 2020 18:00:00 +0100 Subject: [PATCH] Disallow by-name trait parameters --- compiler/src/dotty/tools/dotc/ast/Desugar.scala | 5 +++++ tests/neg/i9886.scala | 2 ++ 2 files changed, 7 insertions(+) create mode 100644 tests/neg/i9886.scala diff --git a/compiler/src/dotty/tools/dotc/ast/Desugar.scala b/compiler/src/dotty/tools/dotc/ast/Desugar.scala index 402e0d6d7e14..032cc6bb4417 100644 --- a/compiler/src/dotty/tools/dotc/ast/Desugar.scala +++ b/compiler/src/dotty/tools/dotc/ast/Desugar.scala @@ -428,6 +428,11 @@ object desugar { } else originalTparams + if mods.is(Trait) then + for vparams <- originalVparamss; vparam <- vparams do + if vparam.tpt.isInstanceOf[ByNameTypeTree] then + report.error(em"implementation restriction: traits cannot have by name parameters", vparam.srcPos) + // Annotations on class _type_ parameters are set on the derived parameters // but not on the constructor parameters. The reverse is true for // annotations on class _value_ parameters. diff --git a/tests/neg/i9886.scala b/tests/neg/i9886.scala new file mode 100644 index 000000000000..765bd389826c --- /dev/null +++ b/tests/neg/i9886.scala @@ -0,0 +1,2 @@ +trait D(l: => Any): // error + def f = l