golo-lang icon indicating copy to clipboard operation
golo-lang copied to clipboard

Package visible java constructor or method not accessible

Open yloiseau opened this issue 7 years ago • 0 comments

Given the Java class

package net.yloiseau.tools;

public class A {
  private final int answer;

  A(int v) { this.answer = v; }

  public static A of(int v) { return new A(v); }

  public int answer() { return this.answer; }

  String meth() { return "A.meth"; }

  static String fun() { return "A.fun"; }
}

and the golo module

module net.yloiseau.tools.Main

function createA = |v| -> net.yloiseau.tools.A(v)
function callFun = -> net.yloiseau.tools.A.fun()
function callMeth = -> net.yloiseau.tools.A.of(42): meth()

All functions should be OK, since the module and the java class are in the same package. Indeed, in

module Main

import net.yloiseau.tools

function main = |args| {
  println(Main.callFun())
  println(Main.createA(42): answer())
  println(Main.callMeth())
}

the first print that call a static function works just fine. However, both the function calling the constructor createA or the method callMeth fail with a NoSuchMethodError. Making the A constructor or meth method public works as expected.

Since the generated class representing the module, and thus the createA and callMeth methods are in the same package as the A class, the method should be found.

Sample files here: https://github.com/yloiseau/golo-tests/tree/master/BUGS/520-package-visibility

yloiseau avatar Mar 15 '18 14:03 yloiseau