Skip to content

A method is not a member of a class even though it is (and can be seen using javap) #13957

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
matviichukv opened this issue Nov 15, 2021 · 10 comments
Labels
itype:bug stat:needs minimization Needs a self contained minimization

Comments

@matviichukv
Copy link

Compiler version

3.1.0

Minimized code

import org.graalvm.graphio._
@main def foo(): Unit = GraphOutput.newBuilder(null).attr("a", "b")

Output

[error] 3 |@main def foo(): Unit = GraphOutput.newBuilder(null).attr("a", "b")
[error]   |                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[error]   |value attr is not a member of org.graalvm.graphio.GraphOutput#Builder[G, N, ?1.CAP] - did you mean org.graalvm.graphio.GraphOutput#Builder[G, N, ?1.CAP].wait?
[error]   |
[error]   |where:    ?1 is an unknown value of type scala.runtime.TypeBox[Nothing, Object]
[error]   |          G  is a type variable with constraint <: Object
[error]   |          N  is a type variable with constraint <: Object

Expectation

It should compile without any errors.

I've made a small repo to easily reproduce this error: https://github.com/matviichukv/scalac_bug . Main.scala fails with this error, while Main.java compiles just fine. Same happens with .embedded method, but all others are fine. attr method is not shown for completion in sbt shell. Invoking it using the java.reflect things calls the method just fine.

Here's the output of javap on the GraphOutput.java from [email protected]

Compiled from "GraphOutput.java"
public final class org.graalvm.graphio.GraphOutput$Builder<G, N, M> {
  static final boolean $assertionsDisabled;
  org.graalvm.graphio.GraphOutput$Builder(org.graalvm.graphio.GraphStructure<G, N, ?, ?>);
  public org.graalvm.graphio.GraphOutput$Builder<G, N, M> protocolVersion(int, int);
  public org.graalvm.graphio.GraphOutput$Builder<G, N, M> embedded(boolean);
  public org.graalvm.graphio.GraphOutput$Builder<G, N, M> types(org.graalvm.graphio.GraphTypes);
  public org.graalvm.graphio.GraphOutput$Builder<G, N, M> blocks(org.graalvm.graphio.GraphBlocks<G, ?, N>);
  public <E, P> org.graalvm.graphio.GraphOutput$Builder<G, N, E> elements(org.graalvm.graphio.GraphElements<E, ?, ?, P>);
  public <E, P> org.graalvm.graphio.GraphOutput$Builder<G, N, E> elementsAndLocations(org.graalvm.graphio.GraphElements<E, ?, ?, P>, org.graalvm.graphio.GraphLocations<E, P, ?>);
  public org.graalvm.graphio.GraphOutput$Builder<G, N, M> attr(java.lang.String, java.lang.Object);
  public org.graalvm.graphio.GraphOutput<G, M> build(java.nio.channels.WritableByteChannel) throws java.io.IOException;
  public org.graalvm.graphio.GraphOutput<G, M> build(org.graalvm.graphio.GraphOutput<?, ?>);
  static {};
}
@DhashS
Copy link

DhashS commented Nov 16, 2021

It’s worth noting that it’s also does not work in scala 2.13

@som-snytt
Copy link
Contributor

Possibly related recent issue where fluent API in Java breaks in Scala #13841

@prolativ
Copy link
Contributor

I cannot reproduce the issue. Even if I check out the scala_bug repository and try to compile the code, everything seems to work fine

@prolativ prolativ added stat:cannot reproduce stat:needs minimization Needs a self contained minimization and removed stat:cannot reproduce labels Nov 16, 2021
@prolativ
Copy link
Contributor

It looks like this works with JDK 8 but not JDK 11. @matviichukv which java version are you using?

@matviichukv
Copy link
Author

I use JDK 11

@prolativ
Copy link
Contributor

Ok, so at least this seems consistent. But still this will need a minimization without an external dependency.

@DhashS
Copy link

DhashS commented Nov 17, 2021

I may be misunderstanding what you're talking about here, but I don't seem to be able to get it working on either 8 or 11.

Minimized repro, which compiles fine using javac

output:

 dhash@hyalite ~/s/r/bug  $ ./testjdk.sh                                                                                                                                                                       main 
[info] welcome to sbt 1.5.1 (AdoptOpenJDK Java 11.0.11)
[info] loading project definition from /home/dhash/synced/radix/bug/11/project
[info] set current project to root-11 (in build file:/home/dhash/synced/radix/bug/11/)
[info] Executing in batch mode. For better performance use sbt's shell
[info] compiling 1 Scala source and 1 Java source to /home/dhash/synced/radix/bug/11/target/scala-2.12/classes ...
[error] /home/dhash/synced/radix/bug/11/src/main/scala/bug.scala:5:10: value args is not a member of GraphOutput.Builder[Nothing,Nothing,_$1]
[error]     flub.args("foo", "bar")
[error]          ^
[error] one error found
[error] (Compile / compileIncremental) Compilation failed
[error] Total time: 2 s, completed Nov 17, 2021, 3:04:49 AM
Compiled from "NoBug.java"
public class NoBug {
  public NoBug();
    Code:
       0: aload_0
       1: invokespecial #1                  // Method java/lang/Object."<init>":()V
       4: return

  public static void main(java.lang.String[]);
    Code:
       0: invokestatic  #2                  // Method GraphOutput.newBuilder:()LGraphOutput$Builder;
       3: astore_1
       4: aload_1
       5: ldc           #3                  // String
       7: ldc           #3                  // String
       9: invokevirtual #4                  // Method GraphOutput$Builder.attr:(Ljava/lang/String;Ljava/lang/Object;)LGraphOutput$Builder;
      12: pop
      13: return
}
[info] welcome to sbt 1.5.1 (AdoptOpenJDK Java 1.8.0_292)
[info] loading project definition from /home/dhash/synced/radix/bug/8/project
[info] set current project to root-8 (in build file:/home/dhash/synced/radix/bug/8/)
[info] Executing in batch mode. For better performance use sbt's shell
[info] compiling 1 Scala source and 1 Java source to /home/dhash/synced/radix/bug/8/target/scala-2.12/classes ...
[error] /home/dhash/synced/radix/bug/8/src/main/scala/bug.scala:5:10: value args is not a member of GraphOutput.Builder[Nothing,Nothing,_$1]
[error]     flub.args("foo", "bar")
[error]          ^
[error] one error found
[error] (Compile / compileIncremental) Compilation failed
[error] Total time: 2 s, completed Nov 17, 2021 3:04:56 AM

I didn't test this with dotty, but I'm assuming it's the same behavior. Setting that up should be trivial, and i'm happy to do it if this isn't a sufficient repro

javac/javap output included to kind of show what's the expected output classfile. It works fine in jshell, and I can run the thing without it dying.

@prolativ
Copy link
Contributor

@DhashS in your example you call flub.args, which is indeed not defined (there's only flub.attr), so how would you expect this to work?

@DhashS
Copy link

DhashS commented Nov 17, 2021

Oh. Serves me right for attempting this at 3am. I'll try and get a legit minimal repro pushed to that repo today 😅. My bad

@som-snytt
Copy link
Contributor

works again on JDK 17.

➜  scalac_bug git:(main) ✗ sbt run
[info] welcome to sbt 1.6.2 (Oracle Corporation Java 17.0.1)
[info] loading project definition from /home/amarki/snips/scalac_bug/project
[info] loading settings for project scalac_bug from build.sbt ...
[info] set current project to hello-world (in build file:/home/amarki/snips/scalac_bug/)

Multiple main classes detected. Select one to run:
 [1] Foo
 [2] foo

Enter number: 2
[info] running foo
[success] Total time: 9 s, completed Feb 9, 2022, 12:04:37 PM

I wonder if I should PR it upstream

diff --git a/build.sbt b/build.sbt
index 07ab1d7..2e1df32 100644
--- a/build.sbt
+++ b/build.sbt
@@ -1,7 +1,7 @@

 // The simplest possible sbt build file is just one line:

-scalaVersion := "3.1.0"
+scalaVersion := "3.1.1"
 // That is, to create a valid sbt build, all you've got to do is define the
 // version of Scala you'd like your project to use.

diff --git a/project/build.properties b/project/build.properties
index 10fd9ee..c8fcab5 100644
--- a/project/build.properties
+++ b/project/build.properties
@@ -1 +1 @@
-sbt.version=1.5.5
+sbt.version=1.6.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
itype:bug stat:needs minimization Needs a self contained minimization
Projects
None yet
Development

No branches or pull requests

4 participants