Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested generics don't compile properly #110

Closed
c-aug opened this issue Aug 20, 2021 · 5 comments
Closed

Nested generics don't compile properly #110

c-aug opened this issue Aug 20, 2021 · 5 comments

Comments

@c-aug
Copy link

c-aug commented Aug 20, 2021

The following code doesn't compile in capnp java v0.1.9:

@0xe49bca963ed0a9f3;

using Java = import "/java.capnp";
$Java.package("com.foo");
$Java.outerClassname("MapOuter");

struct Bar {
    messages @0 :Map(Text, List(Text));
}

struct Map(Key, Value) {
  entries @0 :List(Entry);
  struct Entry {
    key @0 :Key;
    value @1 :Value;
  }
}

It gets errors like

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project foo: Compilation failure: Compilation failure: 
[ERROR] /home/IdeaProjects/foo/target/generated-sources/capnp/MapOuter.java:[106,102] cannot find symbol
[ERROR]   symbol:   class Key_eab2aec14a30ae3e_Reader
[ERROR]   location: class com.foo.MapOuter.Map.Builder<Key_eab2aec14a30ae3e_Builder,Value_eab2aec14a30ae3e_Builder>
[ERROR] /home/IdeaProjects/foo/target/generated-sources/capnp/MapOuter.java:[106,131] cannot find symbol
[ERROR]   symbol:   class Value_eab2aec14a30ae3e_Reader
[ERROR]   location: class com.foo.MapOuter.Map.Builder<Key_eab2aec14a30ae3e_Builder,Value_eab2aec14a30ae3e_Builder>
[ERROR] /home/IdeaProjects/foo/target/generated-sources/capnp/MapOuter.java:[104,202] cannot find symbol
[ERROR]   symbol:   class Key_eab2aec14a30ae3e_Reader
[ERROR]   location: class com.foo.MapOuter.Map.Builder<Key_eab2aec14a30ae3e_Builder,Value_eab2aec14a30ae3e_Builder>
[ERROR] /home/IdeaProjects/foo/target/generated-sources/capnp/MapOuter.java:[104,231] cannot find symbol
[ERROR]   symbol:   class Value_eab2aec14a30ae3e_Reader
[ERROR]   location: class com.foo.MapOuter.Map.Builder<Key_eab2aec14a30ae3e_Builder,Value_eab2aec14a30ae3e_Builder>
[ERROR] /home/IdeaProjects/foo/target/generated-sources/capnp/MapOuter.java:[107,195] cannot find symbol
[ERROR]   symbol:   class Key_eab2aec14a30ae3e_Reader
[ERROR]   location: class com.foo.MapOuter.Map.Builder<Key_eab2aec14a30ae3e_Builder,Value_eab2aec14a30ae3e_Builder>
[ERROR] /home/IdeaProjects/foo/target/generated-sources/capnp/MapOuter.java:[107,224] cannot find symbol
[ERROR]   symbol:   class Value_eab2aec14a30ae3e_Reader
[ERROR]   location: class com.foo.MapOuter.Map.Builder<Key_eab2aec14a30ae3e_Builder,Value_eab2aec14a30ae3e_Builder>
[ERROR] /home/IdeaProjects/foo/target/generated-sources/capnp/MapOuter.java:[110,203] cannot find symbol
[ERROR]   symbol:   class Key_eab2aec14a30ae3e_Reader
[ERROR]   location: class com.foo.MapOuter.Map.Builder<Key_eab2aec14a30ae3e_Builder,Value_eab2aec14a30ae3e_Builder>
[ERROR] /home/IdeaProjects/foo/target/generated-sources/capnp/MapOuter.java:[110,232] cannot find symbol
[ERROR]   symbol:   class Value_eab2aec14a30ae3e_Reader
[ERROR]   location: class com.foo.MapOuter.Map.Builder<Key_eab2aec14a30ae3e_Builder,Value_eab2aec14a30ae3e_Builder>
[ERROR] /home/IdeaProjects/foo/target/generated-sources/capnp/MapOuter.java:[127,105] cannot find symbol
[ERROR]   symbol:   class Key_eab2aec14a30ae3e_Builder
[ERROR]   location: class com.foo.MapOuter.Map.Reader<Key_eab2aec14a30ae3e_Reader,Value_eab2aec14a30ae3e_Reader>
[ERROR] /home/IdeaProjects/foo/target/generated-sources/capnp/MapOuter.java:[127,135] cannot find symbol
[ERROR]   symbol:   class Value_eab2aec14a30ae3e_Builder
[ERROR]   location: class com.foo.MapOuter.Map.Reader<Key_eab2aec14a30ae3e_Reader,Value_eab2aec14a30ae3e_Reader>

The code compiles correctly in the C++ capnp. Note that the Map implementation is copied directly from https://capnproto.org/language.html#generic-types , so this should work.

I think it's the nested generics causing trouble, e.g. this works:

@0xcaebee21746adf65;

using Java = import "/java.capnp";
$Java.package("com.foo");
$Java.outerClassname("PairOuter");

struct Baz {
    messages @0 :List(Pair(Text, List(Text)));
}

struct Pair(Key, Value) {
  key @0 :Key;
  value @1 :Value;
}

Using :Map(Text, Text), or moving Entry to be a top level struct (i.e. moving it outside of Map) still fail.

@dwrensha
Copy link
Member

Hm... that example seems to work for me.

Are you sure that you are using the latest version of the capnpc-java plugin? How did you install it?

@c-aug
Copy link
Author

c-aug commented Aug 20, 2021

This is with the following setup in Maven:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.example</groupId>
    <artifactId>foo</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.capnproto</groupId>
            <artifactId>runtime</artifactId>
            <version>0.1.9</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.expretio.maven.plugins</groupId>
                <artifactId>capnp-maven-plugin</artifactId>
                <version>1.0</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

Compiling is all done via mvn install.

@dwrensha
Copy link
Member

dwrensha commented Aug 20, 2021

Ah, looks like you are using https://github.com/expretio/capnp-maven-plugin, which has not been kept up to date with recent releases. You could open an issue on that repo to request an update. (I'm not sure whether it's being actively maintained.) Meanwhile, you're probably going to need to install canpnc-java more manually.

What I'd like to do eventually is rewrite capnpc-java in Java, to avoid this kind of distribution problem. I opened #111 to track that issue.

@dwrensha
Copy link
Member

My guess is that capnp-maven-plugin does not include this fix: 7da1dc8

@c-aug
Copy link
Author

c-aug commented Aug 23, 2021

Thanks for this. I can confirm that the schema compiles correctly with the latest version of capnproto-java; the problem was the old version in the plugin.

I am happy for you to close this issue if you want.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants