eclipse-archived / golo-lang

Golo - a lightweight dynamic language for the JVM.
http://golo-lang.org/
Eclipse Public License 2.0
478 stars 91 forks source link

Priority in fluent properties #471

Closed yloiseau closed 7 years ago

yloiseau commented 7 years ago

We introduced fluent properties, that allows to call setValue(v) as just value(v) and getValue() or isValue() as value(). However, if a value() method exists, the property is called instead.

For instance, given:

public class A {

  public String getValue() {
    return "getter";
  }

  public Integer value() {
    return 42;
  }
}

and

module Test

function main = |args| {
  println(A(): value())
}

javac A.java && golo golo --files test.golo will print getter, while 42 is expected

danielpetisme commented 7 years ago

Not sure it's a bug .... The current method resolution looks in order for:

So basically it's the normal behavior so now 2 options, either we say it's not a bug and we document the Method finding algo. or we modify the algo.

For me current behavior sounds wise because the classic Java methods (the explicit ones) are used in the first place.

yloiseau commented 7 years ago

I think it qualifies as a bug, since in my example, there is no way to call the value() method.

danielpetisme commented 7 years ago

What would be the correct order? Method, property then augmentation ?

yloiseau commented 7 years ago

I think so. IMO we should involve the "magic" only when "normal" method fails. Don't know if others agree @Artpej @jponge

yloiseau commented 7 years ago

I'd say it can be considered bad design to have both a "bean" interface and a fluent one (as in my example) but it could be useful (e.g. for framework compatibility). Anyway, we should not make such objects unusable.