Crashes the compiler:
T.scala:2: '(' expected but '[' found.
def this[A](x: A, y: A) = {
^
T.scala:4: identifier expected but '}' found.
}
^
Exception in thread "main" java.lang.AssertionError:
field name of class ValDefis not of kind Term, found: scalac.util.Name([error])
at scalac.checkers.CheckTreeNodes.check(CheckTreeNodes.java:137)
at scalac.checkers.CheckTreeNodes.checkNode(CheckTreeNodes.java:815)
at scalac.ast.Tree$ValDef.(Tree.java:110)
at scalac.ast.Tree$ExtValDef.(Tree.java:790)
at scalac.ast.DefaultTreeFactory.ValDef(DefaultTreeFactory.java:62)
at scalac.ast.parser.Parser.param(Parser.java:1456)
at scalac.ast.parser.Parser.paramClause(Parser.java:1427)
at scalac.ast.parser.Parser.funDefOrDcl(Parser.java:1744)
at scalac.ast.parser.Parser.defOrDcl(Parser.java:1642)
at scalac.ast.parser.Parser.templateStatSeq(Parser.java:1939)
at scalac.ast.parser.Parser.templateBody(Parser.java:1866)
at scalac.ast.parser.Parser.classTemplate(Parser.java:1821)
at scalac.ast.parser.Parser.classDef(Parser.java:1797)
at scalac.ast.parser.Parser.clsDef(Parser.java:1669)
at scalac.ast.parser.Parser.topStatSeq(Parser.java:1915)
at scalac.ast.parser.Parser.compilationUnit(Parser.java:2025)
at scalac.ast.parser.Parser.parse(Parser.java:54)
at scalac.ast.parser.ParserPhase.apply(ParserPhase.java:33)
at scalac.Global.compile(Global.java:293)
at scalac.Global.compile(Global.java:266)
at scalac.Main.main(Main.java:32)
I didn't manage to create a non-primary constructor for generic classes
at all! Here's an alternative:
class C[A](x: A) {
def this(x: A, y: A) = {
this(x);
}
}
This one compiles, but yields the following error messages:
T.scala:2: not found: type A
def this(x: A, y: A) = {
^
T.scala:2: not found: type A
def this(x: A, y: A) = {
^
two errors found
|