Skip to content
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

[jvm][java] ClassCastException when casting to String #9585

Closed
aduros opened this issue Jun 14, 2020 · 2 comments
Closed

[jvm][java] ClassCastException when casting to String #9585

aduros opened this issue Jun 14, 2020 · 2 comments
Assignees
Milestone

Comments

@aduros
Copy link
Contributor

aduros commented Jun 14, 2020

This case results in a ClassCastException. Uncommenting the explicit :Dynamic types fixes the crash, but I'm not sure why and I figure it might be a compiler bug?

function getFloat () :Dynamic {
    return 12.34;
}

function getInt () :Dynamic {
    return 666;
}

function getBool () :Dynamic {
    return false;
}

function getArray () :Dynamic {
    return [1,2,3];
}

function getObject () :Dynamic {
    return {x: 0};
}

function main () {
    var value1 /* :Dynamic */ = getFloat();
    var value2 /* :Dynamic */ = getInt();
    var value3 /* :Dynamic */ = getBool();
    var value4 /* :Dynamic */ = getArray();
    var value5 /* :Dynamic */ = getObject();

    trace("Results: "+value1+", "+value2+", "+value3+", "+value4+", "+value5);
}

Thanks!

@Gama11 Gama11 added platform-jvm Everything related to JVM platform-java Everything related to Java labels Jun 14, 2020
@Simn Simn self-assigned this Jun 15, 2020
@Simn
Copy link
Member

Simn commented Jun 15, 2020

This doesn't actually reproduce for me with genjava, only with genjvm. Not quite sure why though, because the dump reveals that all these value locals are typed as String on both targets.

Given that $type still reports them as monomorphs, this must be happening in some filter.

@Simn Simn added feature-type-inference and removed platform-java Everything related to Java platform-jvm Everything related to JVM labels Jun 15, 2020
@Simn
Copy link
Member

Simn commented Jun 15, 2020

Never mind, I had the $type before the trace. The monomorphs get bound to String due to the concatenation, so as far as the generator is concerned this is just a normal concatenation of String instances.

The reason this doesn't fail on genjava (and hxcpp (and probably gencs)) is because the local initialization itself is cast:

		java.lang.String value1 = haxe.lang.Runtime.toString(_Main.Main_Fields_.getFloat());
		java.lang.String value2 = haxe.lang.Runtime.toString(_Main.Main_Fields_.getInt());
		java.lang.String value3 = haxe.lang.Runtime.toString(_Main.Main_Fields_.getBool());
		java.lang.String value4 = haxe.lang.Runtime.toString(_Main.Main_Fields_.getArray());
		java.lang.String value5 = haxe.lang.Runtime.toString(_Main.Main_Fields_.getObject());
HXLINE(  23)		::String value1 = ( (::String)(::_Main::Main_Fields__obj::getFloat()) );
HXLINE(  24)		::String value2 = ( (::String)(::_Main::Main_Fields__obj::getInt()) );
HXLINE(  25)		::String value3 = ( (::String)(::_Main::Main_Fields__obj::getBool()) );
HXLINE(  26)		::String value4 = ( (::String)(::_Main::Main_Fields__obj::getArray()) );
HXLINE(  27)		::String value5 = ( (::String)(::_Main::Main_Fields__obj::getObject()) );

This is somewhat consistent with how our type inference works with regards to Dynamic. I'll have to think about how and where to handle this.

Simn added a commit that referenced this issue Jun 15, 2020
Simn added a commit that referenced this issue Jun 15, 2020
@Simn Simn mentioned this issue Jun 15, 2020
3 tasks
@RealyUniqueName RealyUniqueName added this to the Bugs milestone Jun 15, 2020
@Simn Simn modified the milestones: Bugs, Later Mar 24, 2023
@Simn Simn closed this as completed Nov 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants