-
Notifications
You must be signed in to change notification settings - Fork 181
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
Problem with automatic type casting of anonymous object fields #21
Comments
This is expected. |
That was just for the example. In the actual application there is a socket connection and data serialization/deserialization between these two lines so it's not that easy. In any case why can't the runtime code throw exception or say something in the console, at least in debug mode? |
Dynamic access is basically a way to say "I know what I do" and the Serialisation require you to retype things explicitly if you want to keep Good luck ghfag'n
|
Re-reading the issue, I agree it looks quite strange that you end up with a silent null value there. I'm reopening the issue for discussion. |
Well in cpp type casting are done in many ways and none throws an error. In this case it looks like dynamic cast was used and returned null because So maybe if haxe build a type check with a dynamic cast and ptr comparison Gl.
|
Nope, retyping won't help:
receive in socket, deserialize and retype 2014-02-12 delahee notifications@github.com:
|
I think that when casting from Dynamic to a known class, we should perform a strict check: if the cast is not allowed it should raise an exception. This is similar to what Flash does, and prevents error propagation too deep in the program |
I agree, silently introducing a null value there is going to cause errors later anyway, so it's better to error right there. |
I don't think there will be a problem with performance or anything - On Thu, Feb 13, 2014 at 7:45 PM, Simon Krajewski
|
Hi guys, |
@hughsando while you're at it, please look that Std.is/Std.instance are correctly optimized on hxcpp |
When I define an anonymous object with an array field and then mistakenly cast it later as a list, I receive a "null" pointer in new variable without any errors.
This code produces this result in neko:
and in hxcpp:
I understand that this is my mistake - casting an array as a list. But I didn't receive any meaningful errors during runtime even in debug mode and just making it null feels wrong. I'm not sure if you can do anything with that but that is pretty confusing for someone who didn't stumble on this before. Maybe there is a way to make that cast show some "type casting wrong" error?
The text was updated successfully, but these errors were encountered: