-
-
Notifications
You must be signed in to change notification settings - Fork 57
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
DB::Serializable
deserialization breaks at compile time if a property type includes a DB
type
#205
Comments
I'm surprised this didn't came up before. The following snippet using JSON::Serializable also suffers from this require "json"
struct Builder
include JSON::Serializable
@a : Int32?
end
class A
include JSON::Serializable
@builder : Builder
end
pp! A.from_json(%<{"builder:{"a":1}}>)
|
I regularly trip on that. The code generated by macros won't be interpreted in the context of the macro but where the code is generated, which makes sense but isn't always obvious. I started to always use |
That would be the dual, a type name written in a macro expands at call site and suddenly it binds to something declared in the call site. In this situation we are, for some reason, resolving the type name in the context of the macro ( In your use case as a macro author you can choose to use fully qualified names. But here even declaring Ideally I would like for @jgaskins proposal fix is partial. What happens if the type is generic? How we can fully qualify the type arguments (in a reasonable way)? If we bake a |
This is a good point. Should we instead open this issue on the Crystal compiler? I opened it here because for some reason I hadn't considered that other |
I have the concept of a
Transaction
in my app, and when I added a property whose type included that name (in my case it was aTransaction::Status
enum), it stopped compiling with this error message:But it very clearly exists in my model file. It turns out, the issue is that
DB::Serializable
seesTransaction
and the Crystal compiler interprets that asDB::Transaction
, but the error message doesn't make that clear. I assume this would also be the case if you had top-level types likeError
orDriver
.The text was updated successfully, but these errors were encountered: