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

@typedef on a property fails to build #45

Open
niloc132 opened this issue May 27, 2020 · 1 comment
Open

@typedef on a property fails to build #45

niloc132 opened this issue May 27, 2020 · 1 comment

Comments

@niloc132
Copy link
Contributor

Example JS, as put in the externs/modules/modules.js file:

/**
 * @typedef {(string|number|boolean)}
 */
baz.structural;

Results in this stack trace:

Exception in thread "main" java.lang.UnsupportedOperationException
        at com.google.javascript.rhino.jstype.Property.getScope(Property.java:185)
        at jsinterop.generator.closure.visitor.AbstractClosureVisitor.acceptTypedef(AbstractClosureVisitor.java:175)
        at jsinterop.generator.closure.visitor.AbstractClosureVisitor.accept(AbstractClosureVisitor.java:86)
        at jsinterop.generator.closure.visitor.AbstractClosureVisitor.lambda$acceptProperties$1(AbstractClosureVisitor.java:247)
        at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183)
        at java.base/java.util.TreeMap$KeySpliterator.forEachRemaining(TreeMap.java:2739)
        at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
        at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
        at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
        at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
        at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
        at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:497)
        at jsinterop.generator.closure.visitor.AbstractClosureVisitor.acceptProperties(AbstractClosureVisitor.java:244)
        at jsinterop.generator.closure.visitor.AbstractClosureVisitor.acceptModule(AbstractClosureVisitor.java:195)
        at jsinterop.generator.closure.visitor.AbstractClosureVisitor.accept(AbstractClosureVisitor.java:84)
        at jsinterop.generator.closure.visitor.AbstractClosureVisitor.accept(AbstractClosureVisitor.java:64)
        at jsinterop.generator.closure.visitor.TypeCollector.accept(TypeCollector.java:41)
        at jsinterop.generator.closure.ClosureJsInteropGenerator.generateJavaProgram(ClosureJsInteropGenerator.java:170)
        at jsinterop.generator.closure.ClosureJsInteropGenerator.convert(ClosureJsInteropGenerator.java:68)

This is because the StaticTypedSlot instance passed here to AbstractClosureVisitor.acceptTypedef(...) is a closure Property, which throws when it is asked for its scope:
https://github.com/google/closure-compiler/blob/00ad3658b30221987fbbfe4a59db7e298d68cd72/src/com/google/javascript/rhino/jstype/Property.java#L183-L186

  @Override
  public StaticTypedScope getScope() {
    throw new UnsupportedOperationException();
  }

My workaround for now is to just remove these typedefs and hope they don't matter to the eventual compilation, but they are hard to avoid:

I explored options for a fix briefly, but I'm struggling to find examples in closure-compiler which show how to read a Property to see its type, without either just asking Property.getType() or having a valid "scope" for it.

@niloc132
Copy link
Contributor Author

niloc132 commented Nov 8, 2023

Note that this is preventing proposing an elemental2-webcrypto addition to https://github.com/google/elemental2, since the closure provided externs make extensive use of @typedef:

https://github.com/google/closure-compiler/blob/2dd00e617a6990202032669270807ef222a4cc3c/externs/browser/w3c_webcrypto.js#L45

kohlschuetter added a commit to kohlschutter/jsinterop-generator that referenced this issue Aug 20, 2024
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