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

A constructor is stuck with the first type it's called with. (ClassCastException)

Open utybo opened this issue 7 years ago • 2 comments

This title probably isn't clear enough, so here is the code that is problematic

function myFunction = {
  label("My label is awesome!")
  label(someIcon) # note : someIcon oftype javax.swing.Icon == true
}

function label = |textOrIcon| {
  return javax.swing.JLabel(textOrIcon)
}

The second use of label yields a ClassCastException : java.lang.ClassCastException: Cannot cast javax.swing.Icon to java.lang.String

If reversed (i.e we use label(someIcon) first), this also yields a ClassCastException, except that it's the other way around : java.lang.ClassCastException: Cannot cast java.lang.String to javax.swing.Icon

This shouldn't happen : the JLabel class has two constructors : JLabel(String) and JLabel(Icon). One would except Golo to be able to dynamically call either of the two depending on the object we give.

utybo avatar Jun 27 '17 17:06 utybo

Probably a duplicate of #341 (see https://github.com/eclipse/golo-lang/projects/2)

yloiseau avatar Jun 28 '17 05:06 yloiseau

Alright -- It probably is now that I think about it -- I wasn't sure so I preferred to open an issue with a concrete example.

utybo avatar Jun 28 '17 13:06 utybo