golo-lang
golo-lang copied to clipboard
A constructor is stuck with the first type it's called with. (ClassCastException)
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.
Probably a duplicate of #341 (see https://github.com/eclipse/golo-lang/projects/2)
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.