Parsing: allow primary ctor in object syntactically

It's needed for better recovering for cases of changes like 'class' -> 'object'

The only sensible case when it's may be bad:
class A {
   object B
   constructor() : super()
}

But it seems to be rare, and ';' can be used to separate object from secondary ctor
This commit is contained in:
Denis Zharkov
2015-05-29 18:38:01 +03:00
parent 3f7ca5a586
commit 9c574469ca
6 changed files with 57 additions and 70 deletions
+4 -1
View File
@@ -17,12 +17,15 @@ internal class Example<X, T : Comparable<X>>(protected val x : Foo<X, T>, y : So
class
: modifiers ("class" | "trait") SimpleName
typeParameters?
(modifiers "constructor")? ("(" functionParameter{","} ")")?
primaryConstructor?
(":" annotations delegationSpecifier{","})?
typeConstraints
(classBody? | enumClassBody)
;
primaryConstructor
: (modifiers "constructor")? ("(" functionParameter{","} ")")
;
classBody
: ("{" members "}")?
+1 -1
View File
@@ -111,7 +111,7 @@ parameter
;
object
: "object" SimpleName (":" delegationSpecifier{","})? classBody? // Class body can be optional: this is a declaration
: "object" SimpleName primaryConstructor? (":" delegationSpecifier{","})? classBody? // Class body can be optional: this is a declaration
secondaryConstructor
: modifiers "constructor" valueParameters (":" constructorDelegationCall)? block