manifold-systems / manifold

Manifold is a Java compiler plugin, its features include Metaprogramming, Properties, Extension Methods, Operator Overloading, Templates, a Preprocessor, and more.
http://manifold.systems/
Apache License 2.0
2.43k stars 125 forks source link

java.lang.RuntimeException: expecting 'extends' or 'super' #308

Closed shoaniki closed 3 years ago

shoaniki commented 3 years ago

Describe the bug When defining an extension function with generic types, it is possible to annotate either a parameter type or a type parameter, but annotating both produces the above error. That is to say, @NotNull List<String> is fine, and List<@NotNull String> is fine, but @NotNull List<@NotNull String> causes the error.

It's coming from manifold's TypeNameParser.verifySuperOrExtends and appears to be caused by TypeNameParser not handling type annotations.

To Reproduce Steps to reproduce the behavior:

  1. Define an extension function with a parameter as described above.
  2. Attempt to compile it.

Expected behavior

Desktop (please complete the following information):

Stack trace

java.lang.RuntimeException: expecting 'extends' or 'super'
    at manifold.api.gen.TypeNameParser.verifySuperOrExtends(TypeNameParser.java:142)
    at manifold.api.gen.TypeNameParser.parseType(TypeNameParser.java:73)
    at manifold.api.gen.TypeNameParser.parseParamList(TypeNameParser.java:148)
    at manifold.api.gen.TypeNameParser.parseType(TypeNameParser.java:104)
    at manifold.api.gen.TypeNameParser.parse(TypeNameParser.java:43)
    at manifold.api.gen.SrcType.<init>(SrcType.java:49)
    at manifold.internal.javac.SrcClassUtil.makeSrcType(SrcClassUtil.java:355)
    at manifold.internal.javac.SrcClassUtil.addMethod(SrcClassUtil.java:293)
    at manifold.internal.javac.SrcClassUtil.makeSrcClass(SrcClassUtil.java:151)
    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:292)
    at manifold.internal.javac.ClassSymbols.makeSrcClassStub(ClassSymbols.java:272)
    at manifold.ext.ExtCodeGen.addExtensions(ExtCodeGen.java:120)
    at manifold.ext.ExtCodeGen.make(ExtCodeGen.java:85)
    at manifold.ext.ExtensionManifold.contribute(ExtensionManifold.java:252)
    at manifold.ext.ExtensionManifold.contribute(ExtensionManifold.java:52)
    at manifold.api.type.ResourceFileTypeManifold.contribute(ResourceFileTypeManifold.java:417)
    at manifold.internal.host.SimpleModule.compoundProduce(SimpleModule.java:174)
    at manifold.internal.host.SimpleModule.lambda$produceFile$0(SimpleModule.java:139)
    at manifold.internal.javac.SourceSupplier.getSource(SourceSupplier.java:50)
    at manifold.internal.javac.GeneratedJavaStubFileObject.lambda$new$0(GeneratedJavaStubFileObject.java:40)
    at manifold.util.concurrent.LocklessLazyVar$1.init(LocklessLazyVar.java:91)
    at manifold.util.concurrent.LocklessLazyVar.get(LocklessLazyVar.java:40)
    at manifold.internal.javac.GeneratedJavaStubFileObject.getCharContent(GeneratedJavaStubFileObject.java:101)
    at jdk.compiler/com.sun.tools.javac.api.ClientCodeWrapper$WrappedFileObject.getCharContent(ClientCodeWrapper.java:625)
    ... 122 more
rsmckinney commented 3 years ago

Fix available in release 2021.1.27. Thanks for reporting this!