bug
bug copied to clipboard
Compiler allows empty argument lists for traits
scala> trait T
defined trait T
scala> class C extends T()
defined class C
scala> new T(){}
res0: T = $anon$1@3ffa1b16
scala> class C extends AnyRef with T()
<console>:1: error: traits or objects may not have parameters
class C extends AnyRef with T()
^
Imported From: https://issues.scala-lang.org/browse/SI-6805?orig=1 Reporter: @xeno-by Affected Versions: 2.9.2, 2.10.0
@xeno-by said: This situation happens because in a lot of places in the compiler we silently promote Nil to ListOfNil. Therefore there's code that compensates for such promotions in cases when the receiver is actually nullary.
Hence it's currently impossible to do the validation for New, but as of late it's possible to do the validation for parent types as in extends T() and new T(){}. So the fix should be a real simple change to typedParentType.
On the other hand, do we really want to fix this thing given that we plan to introduce trait parameters in the near future? Martin, could you please comment?
@odersky said: I think it should have low priority. No need for a fix.
Scala 3 does have trait parameters now
scala 2.13.11> trait T
trait T
scala 2.13.11> class C extends AnyRef with T()
class C
What he meant is that inMixinPosition is now also checked in typedParentType and falls under the fix.
trait T() is able to fail in parser.