ceylon / ceylon.ast

Apache License 2.0
18 stars 3 forks source link

Error converting from rh to AnonymousArgumentInfo #95

Closed jvasileff closed 9 years ago

jvasileff commented 9 years ago

Redhat anonymous SpecifiedArgument's do have an identifier, causing an incorrect test in namedArgumentToCeylon.

For

                C().foo {
                    i++;
                    b = i++;
                };

there is a failure processing the token, since an AnonymousArgument is mistaken for a SpecifiedArgumentInfo.

The RH tree is (note the a identifier):

|  |  |  |  |  |  + {} [NamedArgumentList] (10:12-13:4)
|  |  |  |  |  |  |  +  [SpecifiedArgument] (11:8-11:11) : value C.foo.a => Integer
|  |  |  |  |  |  |  |  + a [Identifier]
|  |  |  |  |  |  |  |  +  [SpecifierExpression] (11:8-11:10)
|  |  |  |  |  |  |  |  |  +  [Expression] (11:8-11:10) : Integer
|  |  |  |  |  |  |  |  |  |  + ++ [PostfixIncrementOp] (11:8-11:10) : Integer
|  |  |  |  |  |  |  |  |  |  |  +  [BaseMemberExpression] (11:8-11:8) : Integer : i : value run.i => Integer
|  |  |  |  |  |  |  |  |  |  |  |  + i [Identifier] (11:8-11:8)
|  |  |  |  |  |  |  |  |  |  |  |  +  [InferredTypeArguments]
|  |  |  |  |  |  |  +  [SpecifiedArgument] (12:8-12:15) : value C.foo.b => Integer
|  |  |  |  |  |  |  |  + b [Identifier] (12:8-12:8)
|  |  |  |  |  |  |  |  + = [SpecifierExpression] (12:10-12:14)
|  |  |  |  |  |  |  |  |  +  [Expression] (12:12-12:14) : Integer
|  |  |  |  |  |  |  |  |  |  + ++ [PostfixIncrementOp] (12:12-12:14) : Integer
|  |  |  |  |  |  |  |  |  |  |  +  [BaseMemberExpression] (12:12-12:12) : Integer : i : value run.i => Integer
|  |  |  |  |  |  |  |  |  |  |  |  + i [Identifier] (12:12-12:12)
|  |  |  |  |  |  |  |  |  |  |  |  +  [InferredTypeArguments]

possible fix (works):

diff --git i/source/ceylon/ast/redhat/AnonymousArgument.ceylon w/source/ceylon/ast/redhat/AnonymousArgument.ceylon
index b9381d8..ee5fc17 100644
--- i/source/ceylon/ast/redhat/AnonymousArgument.ceylon
+++ w/source/ceylon/ast/redhat/AnonymousArgument.ceylon
@@ -15,7 +15,7 @@ import com.redhat.ceylon.compiler.typechecker.tree {
  does not convert those and will throw an exception instead!"
 shared AnonymousArgument anonymousArgumentToCeylon(JSpecifiedArgument anonymousArgument, Anything(JNode,Node) update = noop) {
     "Must be anonymous"
-    assert (!anonymousArgument.identifier exists,
+    assert (!anonymousArgument.identifier?.mainToken exists,
         !anonymousArgument.specifierExpression.mainToken exists);
     value result = AnonymousArgument(expressionToCeylon(anonymousArgument.specifierExpression.expression, update));
     update(anonymousArgument, result);
diff --git i/source/ceylon/ast/redhat/NamedArgument.ceylon w/source/ceylon/ast/redhat/NamedArgument.ceylon
index 66508e6..b3ce365 100644
--- i/source/ceylon/ast/redhat/NamedArgument.ceylon
+++ w/source/ceylon/ast/redhat/NamedArgument.ceylon
@@ -19,7 +19,7 @@ shared NamedArgument namedArgumentToCeylon(JNamedArgument namedArgument, Anythin
     assert (is JSpecifiedArgument|JTypedArgument namedArgument);
     switch (namedArgument)
     case (is JSpecifiedArgument) {
-        if (!namedArgument.identifier exists) {
+        if (!namedArgument.identifier exists || !namedArgument.identifier.mainToken exists) {
             // anonymous argument
             return anonymousArgumentToCeylon(namedArgument, update);
         } else {
lucaswerkmeister commented 9 years ago

Why not

-        if (!namedArgument.identifier exists) {
+        if (!namedArgument.identifier?.mainToken exists) {

in the second diff?

Otherwise, the fix looks good to me.

jvasileff commented 9 years ago

Yes. The original is the 3am version. I'll submit a PR a bit later if you don't beat me to it.

lucaswerkmeister commented 9 years ago

Sure, I’ll wait :)

lucaswerkmeister commented 9 years ago

Should be fixed by #96.