-
-
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
Error: undefined method 'to_unsafe' for Foo (compile-time type is MyModule) #14920
Comments
Reduced further: module MyModule; end
class Foo
include MyModule
end
a = Foo.new.as(MyModule)
if a.responds_to?(:object_id)
else
a.to_unsafe
end The only implementation of Before #14728, the The if condition restricts |
Modules are similar to abstract classes in this aspect so I don't think they can be exhausted like that. |
Ah, right. That's unfortunate. The change from +if value.responds_to?(:object_id)
"object_id: #{value.object_id}"
+else
+ value.to_unsafe
+end But now it crashes on types that actually do implement it. 🤷 |
Trying to refactor the control flow as a workaround causes an ICE: module MyModule; end
class Foo
include MyModule
end
a = Foo.new.as(MyModule)
if !a.responds_to?(:object_id) && a.responds_to?(:to_unsafe)
a.to_unsafe
else
a.object_id
end # BUG: trying to downcast (Foo | MyModule) (Crystal::MixedUnionType) <- Foo (Crystal::NonGenericClassType) (Exception) |
Noticed a regression in nightly Athena CI. Was able to reduce it to the following:
Seems to be a regression from #14728 in that
a
in this case is typed as an interface module so doesn't actually respond to#object_id
or#to_unsafe
. At least that's what I'm getting from the full trace:The text was updated successfully, but these errors were encountered: