Skip to content

Compilation failure when using annotations in generic type parameters of extension methods #709

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

Open
EotT123 opened this issue May 16, 2025 · 0 comments

Comments

@EotT123
Copy link
Contributor

EotT123 commented May 16, 2025

Using annotations on generic type parameters in an extension method causes a compilation failure in Manifold.

@Extension
public class StringExt {
    //                           |
    //                           |
    //                           v
    public static <T extends @Nullable Object> T test1(@This String text, Function<String, T> mapper) {
        return mapper.apply(text);
    }

    //                                                                 |
    //                                                                 |
    //                                                                 v
    public static <T> T test2(@This String text, Function<String, @Nullable T> mapper) {
        return mapper.apply(text);
    }
}

This results in a rather informative error: An unknown compilation problem occurred when compiling.

I had to run the compilation process in debug mode to track down the actual cause:

manifold.api.gen.TypeNameParserException: expecting 'extends' or 'super'
	at manifold.api.gen.TypeNameParser.verifySuperOrExtends(TypeNameParser.java:160)
	at manifold.api.gen.TypeNameParser.parseType(TypeNameParser.java:91)
	at manifold.api.gen.TypeNameParser.parseCompoundType(TypeNameParser.java:151)
	at manifold.api.gen.TypeNameParser.parseType(TypeNameParser.java:92)
	at manifold.api.gen.TypeNameParser.parse(TypeNameParser.java:43)
	at manifold.api.gen.SrcType.<init>(SrcType.java:61)
	at manifold.internal.javac.SrcClassUtil.makeTypeVarType(SrcClassUtil.java:1109)
	at manifold.internal.javac.SrcClassUtil.addMethod(SrcClassUtil.java:370)
	at manifold.internal.javac.SrcClassUtil.makeSrcClass(SrcClassUtil.java:156)
	at manifold.internal.javac.SrcClassUtil.makeStub(SrcClassUtil.java:81)
	at manifold.internal.javac.SrcClassUtil.makeStub(SrcClassUtil.java:75)
	at manifold.internal.javac.ClassSymbols.makeSrcClassStub(ClassSymbols.java:327)
	at manifold.internal.javac.ClassSymbols.makeSrcClassStub(ClassSymbols.java:307)
	at manifold.ext.ExtCodeGen.addExtensions(ExtCodeGen.java:259)
	at manifold.ext.ExtCodeGen.make(ExtCodeGen.java:99)
	at manifold.ext.ExtensionManifold.contribute(ExtensionManifold.java:360)
	at manifold.ext.ExtensionManifold.contribute(ExtensionManifold.java:54)

Removing the @Nullable annotation from the generic bound resolves the issue,

EotT123 pushed a commit to EotT123/manifold-test that referenced this issue May 16, 2025
EotT123 pushed a commit to EotT123/manifold-test that referenced this issue May 16, 2025
EotT123 pushed a commit to EotT123/manifold-test that referenced this issue May 16, 2025
EotT123 pushed a commit to EotT123/manifold-test that referenced this issue May 17, 2025
EotT123 pushed a commit to EotT123/manifold-test that referenced this issue May 23, 2025
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

1 participant