ceylon / ceylon.ast

Apache License 2.0
18 stars 3 forks source link

Bug processing typechecked `package` and `module` decs #105

Closed jvasileff closed 8 years ago

jvasileff commented 8 years ago

Section 6.10.2. Package and module references allows package-name-less package reference expressions (package):

If there is no explicit package name, the package reference is to the package in which the package reference expression occurs.

but ceylon.ast.redhat blows up with:

Exception in thread "main" ceylon.language.AssertionError "Assertion failed
    violated nonempty components = CeylonIterable(fullPackageName.identifiers).collect(propagateUpdate(pIdentifierToCeylon, update))"
    at ceylon.ast.redhat.fullPackageNameToCeylon_.fullPackageNameToCeylon(FullPackageName.ceylon:17)
    at ceylon.ast.redhat.packageDecToCeylon_.packageDecToCeylon(PackageDec.ceylon:16)
    at ceylon.ast.redhat.decToCeylon_.decToCeylon(Dec.ceylon:32)
    at ceylon.ast.redhat.primaryToCeylon_.primaryToCeylon(Primary.ceylon:47)

This is supported by the api of PackageDec, as packageName is optional.

jvasileff commented 8 years ago

@lucaswerkmeister re you're Gitter question

it looks like you’ve managed to get a package literal with a non-null, but empty import path how?

it must be that the type checker fills in this info when full type checking is performed. For the program:

Anything p = `package`;

I get:

$ ceylon compile-dart --verbose=ast,rhAst
...
-- Redhat AST simple/run.ceylon
+  [CompilationUnit] (1:0-1:22)
|  +  [ImportList]
|  +  [AttributeDeclaration] (1:0-1:22) : value p => Anything
|  |  +  [AnnotationList]
|  |  + p [Identifier] (1:9-1:9)
|  |  +  [BaseType] (1:0-1:7) : Anything : class Anything()
|  |  |  + Anything [Identifier] (1:0-1:7)
|  |  + = [SpecifierExpression] (1:11-1:21)
|  |  |  +  [Expression] (1:13-1:21) : Package
|  |  |  |  + `` [PackageLiteral] (1:13-1:21) : Package
|  |  |  |  |  +  [ImportPath]

------------------------------------------------------------
                    ** Compiler bug! **
------------------------------------------------------------
Assertion failed
    violated nonempty components = CeylonIterable(fullPackageName.identifiers).collect(propagateUpdate(pIdentifierToCeylon, update))

was encountered while compiling the file:

    source/simple/run.ceylon
------------------------------------------------------------
Exception in thread "main" ceylon.language.AssertionError "Assertion failed
    violated nonempty components = CeylonIterable(fullPackageName.identifiers).collect(propagateUpdate(pIdentifierToCeylon, update))"
    at ceylon.ast.redhat.fullPackageNameToCeylon_.fullPackageNameToCeylon(FullPackageName.ceylon:17)
    at ceylon.ast.redhat.packageDecToCeylon_.packageDecToCeylon(PackageDec.ceylon:16)
    at ceylon.ast.redhat.decToCeylon_.decToCeylon(Dec.ceylon:32)
jvasileff commented 8 years ago

Ah, looks like ExpressionVisitor.java is the null hater (or null burier?):

https://github.com/ceylon/ceylon/blob/3d92c0cb6faf9b5d2c93635f82b27ee1c8e26c89/typechecker/src/com/redhat/ceylon/compiler/typechecker/analyzer/ExpressionVisitor.java#L8841

Module literals may also be affected.

lucaswerkmeister commented 8 years ago

Indeed it does: ExpressionVisitor.java:8847. I thought it would create a proper import path with the correct components, but it looks like it doesn’t. Alright.

jvasileff commented 8 years ago

Github tells me I beat you by 1s :)

lucaswerkmeister commented 8 years ago

GitHub doesn’t even tell me second-precise timestamps :(

jvasileff commented 8 years ago

So yes, Anything p = `module`; also fails with:

Exception in thread "main" ceylon.language.AssertionError "Assertion failed
    violated nonempty components = CeylonIterable(fullPackageName.identifiers).collect(propagateUpdate(pIdentifierToCeylon, update))"
    at ceylon.ast.redhat.fullPackageNameToCeylon_.fullPackageNameToCeylon(FullPackageName.ceylon:17)
    at ceylon.ast.redhat.moduleDecToCeylon_.moduleDecToCeylon(ModuleDec.ceylon:16)
    at ceylon.ast.redhat.decToCeylon_.decToCeylon(Dec.ceylon:33)
    at ceylon.ast.redhat.primaryToCeylon_.primaryToCeylon(Primary.ceylon:47)
lucaswerkmeister commented 8 years ago

Should be fixed in branch fix105, can you try it out?

(class and interface should be fine afaict.)

jvasileff commented 8 years ago

works great, thanks!

BTW, a nice tool for testing this sort of thing is ceylon compile-dart --verbose=ast,rhAst :)

lucaswerkmeister commented 8 years ago

Alright, pushed to master then :)

And it seems like your compiler is a great way to debug ceylon.ast on typechecked ASTs, so I guess I’ll install it :D

On 08.12.2015 01:17, John Vasileff wrote:

works great, thanks!

BTW, a nice tool for testing this sort of thing is |ceylon compile-dart --verbose=ast,rhAst| :)

— Reply to this email directly or view it on GitHub https://github.com/ceylon/ceylon.ast/issues/105#issuecomment-162712618.