-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
.as?
doesn't behave like .as
when casting reference to pointer
#14491
Comments
I have some vague recollection that this had been mentioned before. But |
We talked about it in on slack a while back 🙊 The pseudo methods are implemented as the
|
Nope, that doesn't fix anything: the type is correctly inferred as crystal/src/compiler/crystal/codegen/codegen.cr Line 1401 in 944bee2
|
Hum, this is worst than just references: foo = Pointer(Int32).new(0xdeadbeef)
p foo.as(Int32*) # => Pointer(Void)@xdeadbeef
p foo.as?(Int32*) # => Pointer(Void)@xdeadbeef foo = Pointer(Int32).new(0xdeadbeef)
p foo.as(Void*) # => Pointer(Void)@xdeadbeef
p foo.as?(Void*) # => nil I'm pretty sure the codegen linked above is the culprit: it doesn't account for pointers at all. That being said, I'm not sure how to properly fix it... |
The behaviour is identical in the interpreter. So if it's a codegen issue, the interpreter has the same implementation. |
Confirmed: the |
The interpreter behaves just like the LLVM codegen: it immediately returns |
Related: #11058 |
I noticed
Reference#as?(Void*)
doesn't behave likeReference#as(Void*)
. For example:I believe this is an error in
.as?
. The only difference between these two pseudo methods should be in error handling (raise vs. nil), and casting a reference to a pointer is an acceptable behavior (a reference is a pointer).The text was updated successfully, but these errors were encountered: