ceylon / ceylon-compiler

DEPRECATED
GNU General Public License v2.0
138 stars 36 forks source link

various exceptions running `ceylon test com.module` #2388

Closed jvasileff closed 8 years ago

jvasileff commented 8 years ago

I haven't been able to create a small test cases yet, so I'll dump what I have for now and try again later if necessary.

Case 1: Issue with an object value that extends a Java class in a top-level function

Unless this statement (https://github.com/jvasileff/ceylon-dart/blob/master/ceylon-dart-compiler/source/com/vasileff/ceylon/dart/compiler/compile.ceylon#L47) is uncommented, I get:

$ ceylon test --test com.vasileff.ceylon.dart.compiler com.vasileff.ceylon.dart
ceylon test: Failed to resolve com.vasileff.ceylon.dart.compiler.compile_$2$1anonymous_1_
com.redhat.ceylon.model.loader.ModelResolutionException: Failed to resolve com.vasileff.ceylon.dart.compiler.compile_$2$1anonymous_1_
    at com.redhat.ceylon.model.loader.AbstractModelLoader.convertToDeclaration(AbstractModelLoader.java:1529)
    at com.redhat.ceylon.model.loader.AbstractModelLoader.addLocalDeclarations(AbstractModelLoader.java:2648)
    at com.redhat.ceylon.model.loader.AbstractModelLoader.complete(AbstractModelLoader.java:4030)
    at com.redhat.ceylon.model.loader.model.LazyFunction.load(LazyFunction.java:83)
    at com.redhat.ceylon.model.loader.model.LazyFunction.getTypeDeclaration(LazyFunction.java:142)
    at com.redhat.ceylon.compiler.java.runtime.metamodel.Predicates$4.accept(Predicates.java:213)
    at com.redhat.ceylon.compiler.java.runtime.metamodel.Predicates$4.accept(Predicates.java:209)
    at com.redhat.ceylon.compiler.java.runtime.metamodel.Predicates$And.accept(Predicates.java:120)
    at com.redhat.ceylon.compiler.java.runtime.metamodel.decl.PackageImpl.filteredMembers(PackageImpl.java:142)
    at com.redhat.ceylon.compiler.java.runtime.metamodel.decl.PackageImpl.annotatedMembers(PackageImpl.java:129)
    at ceylon.test.core.findCandidatesInPackage_.findCandidatesInPackage(DefaultTestRunner.ceylon:197)
    at ceylon.test.core.findCandidatesInPackageLiteral_.findCandidatesInPackageLiteral(DefaultTestRunner.ceylon:269)

Case 2: Class member of a generic java type

For https://github.com/jvasileff/jl4c-guava/blob/master/source/com/vasileff/jl4c/guava/collect/ImmutableSetBuilder.ceylon

$ ceylon test com.vasileff.jl4c.guava
ceylon test: Error while loading the com.vasileff.jl4c.guava/0.0.1 module:
 Error while resolving type of getter 'delegate$priv$' for com.vasileff.jl4c.guava.collect::ImmutableSetBuilder:
 Could not find type 'E'
com.redhat.ceylon.model.loader.ModelResolutionException: Error while loading the com.vasileff.jl4c.guava/0.0.1 module:
 Error while resolving type of getter 'delegate$priv$' for com.vasileff.jl4c.guava.collect::ImmutableSetBuilder:
 Could not find type 'E'
    at com.redhat.ceylon.compiler.java.runtime.model.RuntimeModelLoader$1.reportError(RuntimeModelLoader.java:209)
    at com.redhat.ceylon.model.typechecker.model.UnknownType.reportErrors(UnknownType.java:94)
    at com.redhat.ceylon.compiler.java.runtime.metamodel.Metamodel.getMetamodel(Metamodel.java:595)
    at com.redhat.ceylon.compiler.java.runtime.metamodel.decl.ValueDeclarationImpl.<init>(ValueDeclarationImpl.java:52)
    at com.redhat.ceylon.compiler.java.runtime.metamodel.Metamodel.getOrCreateMetamodel(Metamodel.java:425)
    at com.redhat.ceylon.compiler.java.runtime.metamodel.decl.ClassOrInterfaceDeclarationImpl.addDeclarationTo(ClassOrInterfaceDeclarationImpl.java:114)
    at com.redhat.ceylon.compiler.java.runtime.metamodel.decl.ClassOrInterfaceDeclarationImpl.init(ClassOrInterfaceDeclarationImpl.java:99)
    at com.redhat.ceylon.compiler.java.runtime.metamodel.decl.ClassDeclarationImpl.init(ClassDeclarationImpl.java:58)
    at com.redhat.ceylon.compiler.java.runtime.metamodel.decl.ClassOrInterfaceDeclarationImpl.checkInit(ClassOrInterfaceDeclarationImpl.java:163)
    at com.redhat.ceylon.compiler.java.runtime.metamodel.decl.ClassOrInterfaceDeclarationImpl.filteredMembers(ClassOrInterfaceDeclarationImpl.java:231)
    at com.redhat.ceylon.compiler.java.runtime.metamodel.decl.ClassOrInterfaceDeclarationImpl.annotatedMemberDeclarations(ClassOrInterfaceDeclarationImpl.java:205)
    at ceylon.test.core.findCandidatesInClass_.findCandidatesInClass(DefaultTestRunner.ceylon:207)
    at ceylon.test.core.findCandidatesInPackage_.findCandidatesInPackage(DefaultTestRunner.ceylon:201)
    at ceylon.test.core.findCandidatesInModule_.findCandidatesInModule(DefaultTestRunner.ceylon:192)

Case 3: Cannot run ceylon test on ceylon.transaction

Trying ceylon test ceylon.transaction in the ceylon-sdk directory results in:

$ ceylon test ceylon.transaction
ceylon test: Error while loading the ceylon.transaction/1.2.0 module:
 Declaration 'javax.transaction.xa.XAResource' could not be found in module 'ceylon.transaction' or its imported modules but was found in the non-imported module 'javax.transaction'
com.redhat.ceylon.model.loader.ModelResolutionException: Error while loading the ceylon.transaction/1.2.0 module:
 Declaration 'javax.transaction.xa.XAResource' could not be found in module 'ceylon.transaction' or its imported modules but was found in the non-imported module 'javax.transaction'
    at com.redhat.ceylon.compiler.java.runtime.model.RuntimeModelLoader$1.reportError(RuntimeModelLoader.java:209)
    at com.redhat.ceylon.model.typechecker.model.UnknownType.reportErrors(UnknownType.java:94)
    at com.redhat.ceylon.compiler.java.runtime.metamodel.Metamodel.getMetamodel(Metamodel.java:595)
    at com.redhat.ceylon.compiler.java.runtime.metamodel.decl.ValueDeclarationImpl.<init>(ValueDeclarationImpl.java:52)
    at com.redhat.ceylon.compiler.java.runtime.metamodel.Metamodel.getOrCreateMetamodel(Metamodel.java:425)
    at com.redhat.ceylon.compiler.java.runtime.metamodel.decl.ClassOrInterfaceDeclarationImpl.addDeclarationTo(ClassOrInterfaceDeclarationImpl.java:114)
    at com.redhat.ceylon.compiler.java.runtime.metamodel.decl.ClassOrInterfaceDeclarationImpl.init(ClassOrInterfaceDeclarationImpl.java:99)
    at com.redhat.ceylon.compiler.java.runtime.metamodel.decl.ClassDeclarationImpl.init(ClassDeclarationImpl.java:58)
    at com.redhat.ceylon.compiler.java.runtime.metamodel.decl.ClassOrInterfaceDeclarationImpl.checkInit(ClassOrInterfaceDeclarationImpl.java:163)
    at com.redhat.ceylon.compiler.java.runtime.metamodel.decl.ClassOrInterfaceDeclarationImpl.filteredMembers(ClassOrInterfaceDeclarationImpl.java:231)
    at com.redhat.ceylon.compiler.java.runtime.metamodel.decl.ClassOrInterfaceDeclarationImpl.annotatedMemberDeclarations(ClassOrInterfaceDeclarationImpl.java:205)
    at ceylon.test.core.findCandidatesInClass_.findCandidatesInClass(DefaultTestRunner.ceylon:207)
    at ceylon.test.core.findCandidatesInPackage_.findCandidatesInPackage(DefaultTestRunner.ceylon:201)
    at ceylon.test.core.findCandidatesInModule_.findCandidatesInModule(DefaultTestRunner.ceylon:192)
FroMage commented 8 years ago

Do those also happen with ceylon run?

jvasileff commented 8 years ago

No, just test.

FroMage commented 8 years ago

Weird

FroMage commented 8 years ago

I can't reproduce the third one. It works for me. Are you sure you're using the right ceylon command?

FroMage commented 8 years ago

I can't reproduce the first because the file does not exist where you point it, and where it is, line 47 points to an import }, so that's probably not the line you meant.

FroMage commented 8 years ago

I can reproduce the second:

atlantis stephane 09:27 jl4c-guava $ ../ceylon-dist/dist/bin/ceylon test com.vasileff.jl4c.guava
ceylon test: Error while loading the com.vasileff.jl4c.guava/0.0.1 module:
 Error while resolving type of getter 'delegate$priv$' for com.vasileff.jl4c.guava.collect::ImmutableMapBuilder:
 Could not find type 'K'
com.redhat.ceylon.model.loader.ModelResolutionException: Error while loading the com.vasileff.jl4c.guava/0.0.1 module:
 Error while resolving type of getter 'delegate$priv$' for com.vasileff.jl4c.guava.collect::ImmutableMapBuilder:
 Could not find type 'K'
    at com.redhat.ceylon.compiler.java.runtime.model.RuntimeModelLoader$1.reportError(RuntimeModelLoader.java:209)
    at com.redhat.ceylon.model.typechecker.model.UnknownType.reportErrors(UnknownType.java:94)
    at com.redhat.ceylon.compiler.java.runtime.metamodel.Metamodel.getMetamodel(Metamodel.java:595)
    at com.redhat.ceylon.compiler.java.runtime.metamodel.decl.ValueDeclarationImpl.<init>(ValueDeclarationImpl.java:48)
    at com.redhat.ceylon.compiler.java.runtime.metamodel.Metamodel.getOrCreateMetamodel(Metamodel.java:425)
    at com.redhat.ceylon.compiler.java.runtime.metamodel.decl.ClassOrInterfaceDeclarationImpl.addDeclarationTo(ClassOrInterfaceDeclarationImpl.java:114)
    at com.redhat.ceylon.compiler.java.runtime.metamodel.decl.ClassOrInterfaceDeclarationImpl.init(ClassOrInterfaceDeclarationImpl.java:99)
    at com.redhat.ceylon.compiler.java.runtime.metamodel.decl.ClassDeclarationImpl.init(ClassDeclarationImpl.java:58)
    at com.redhat.ceylon.compiler.java.runtime.metamodel.decl.ClassOrInterfaceDeclarationImpl.checkInit(ClassOrInterfaceDeclarationImpl.java:163)
    at com.redhat.ceylon.compiler.java.runtime.metamodel.decl.ClassOrInterfaceDeclarationImpl.filteredMembers(ClassOrInterfaceDeclarationImpl.java:231)
    at com.redhat.ceylon.compiler.java.runtime.metamodel.decl.ClassOrInterfaceDeclarationImpl.annotatedMemberDeclarations(ClassOrInterfaceDeclarationImpl.java:205)
    at ceylon.test.core.findCandidatesInClass_.findCandidatesInClass(DefaultTestRunner.ceylon:207)
    at ceylon.test.core.findCandidatesInPackage_.findCandidatesInPackage(DefaultTestRunner.ceylon:201)
FroMage commented 8 years ago

So that one is because we generate:

@TypeInfo("com.google.common.collect::ImmutableMap<K,V>.Builder<Key,Item>")

Which is wrong, since K does not exist. It should be Key I guess. Now, whose fault is it?

FroMage commented 8 years ago

Damn, when I try to reproduce in a test I get the correct signature:

@TypeInfo("com.redhat.ceylon.compiler.java.test.issues.bug23xx::Bug2388Java.Builder<Key,Value>")
    private final .com.redhat.ceylon.compiler.java.test.issues.bug23xx.Bug2388Java.Builder<Key, Value> getDelegate$priv$() {
        return delegate;
    }
FroMage commented 8 years ago

Ah, I can reproduce it for that guava type. Could be something module-related?

FroMage commented 8 years ago

No, it has to do with overloading. If the constructor of Builder is overloaded I can reproduce it without Guava:

@TypeInfo("com.redhat.ceylon.compiler.java.test.issues.bug23xx::Bug2388Java<K,V>.Builder<Key,Value>")
FroMage commented 8 years ago

@gavinking do you remember what the right form for a qualifying's static type is in Java? Should it have type arguments? I always forget. I guess it should not, as they may have no relation to the qualified type's arguments so we can't infer them.

gavinking commented 8 years ago

I believe you should leave them out. But no, I don't quite remember.

FroMage commented 8 years ago

So it looks like Declaration.getMemberContainerType() is to blame because it returns a Type for the container even for that static inner class. I can make it return null for the container of staticallyImportable declarations (except Java enums which have a virtual container type that is required).

FroMage commented 8 years ago

So that second test is resolved, and the other ones require user intervention, moving to 1.3 for now.

jvasileff commented 8 years ago

On the third one, strange. Maybe it would work if I recompiled everything with Java 7? But I think the command is correct:

jvasileff@lynx:ceylon-sdk$ ceylon test ceylon.transaction
ceylon test: Error while loading the ceylon.transaction/1.2.0 module:
 Declaration 'javax.transaction.xa.XAResource' could not be found in module 'ceylon.transaction' or its imported modules but was found in the non-
jvasileff commented 8 years ago

On the first one, yes, sorry, the code just changed. It's:

https://github.com/jvasileff/ceylon-dart/blob/90f941f9adc4875180bd61036bfaec63ab3b8d70/ceylon-dart-compiler/source/com/vasileff/ceylon/dart/compile.ceylon#L57

or

    value virtualFiles = listings.indexed.map((listing) => object
            satisfies VirtualFile {
        shared actual
        List<out VirtualFile> children
            =>  javaList {};
    ...

where VirtualFile is com.redhat.ceylon.compiler.typechecker.io::VirtualFile. Although, perhaps the problem here is with javaList {}, which I think involves guava. I'll have to try removing that.

jvasileff commented 8 years ago

Nope, still happens without javaList. So VirtualFile is the likely suspect.

FroMage commented 8 years ago

On the third one, strange. Maybe it would work if I recompiled everything with Java 7? But I think the command is correct:

But this works for me, which is what's weird.

jvasileff commented 8 years ago

Of course, I can't reproduce # 1 with:

shared void run() {
    value vf = object satisfies VirtualFile {
        shared actual List<out VirtualFile> children => nothing;
        shared actual Integer compareTo(VirtualFile other) => nothing;
        shared actual Boolean folder => nothing;
        shared actual InputStream inputStream => nothing;
        shared actual String name => nothing;
        shared actual String path => nothing;
        shared actual Boolean \iexists() => nothing;
    };
}

that would be too easy.

jvasileff commented 8 years ago

gotit

jvasileff commented 8 years ago

This fails (very strange once you start trying variations):

import java.io {
    InputStream
}
import java.util {
    List
}
import com.redhat.ceylon.compiler.typechecker.io {
    VirtualFile
}

shared void run({String*} dummy = {}) {
    value vfs = [].map((x) => object satisfies VirtualFile {
        shared actual List<VirtualFile> children => nothing;
        shared actual Integer compareTo(VirtualFile other) => nothing;
        shared actual Boolean folder => nothing;
        shared actual InputStream inputStream => nothing;
        shared actual String name => nothing;
        shared actual String path => nothing;
        shared actual Boolean \iexists() => nothing;
    });
}

with

native("jvm")
module simple "1.0.0" {
    import java.base "8";
    import com.redhat.ceylon.typechecker "1.2.0";
}
jvasileff commented 8 years ago

Changing

shared void run({String*} dummy = {}) {

to any of these

shared void run() {
shared void run({String*} dummy) {
shared void run([String*] dummy = []) {
shared void run({String+} dummy = {""}) {

makes the problem go away, or at least masks it.

jvasileff commented 8 years ago

Here's a shorter version (no imports):

void run(Anything dummy = {}) {
    value f = () => object {};
}

VirtualFile was a red herring.

FroMage commented 8 years ago

I fixed the first one now, thanks. Narrowing it down made it much easier for me.

So we're left with the third one. Are you saying you're having the problem with Java 8 then? Because myself with Java 7 I can't reproduce.

FroMage commented 8 years ago

I just recompiled everything with Java 8 and ran it without issues.

FroMage commented 8 years ago

OK now I understand, I was running ceylon test test.ceylon.transation, not ceylon test ceylon.transaction. I can reproduce. Sorry about that.

FroMage commented 8 years ago

OK, the last one is due to the javax.transaction.xa.XAResource being in more than one package. I can't fix that in time for 1.2, and it's a dupe of #1827, so I'm going to close this.