-
Notifications
You must be signed in to change notification settings - Fork 122
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
Compile generic types in signatures using the correct constant #412
Compile generic types in signatures using the correct constant #412
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather that we solve this in a more generic fashion by binding the constant value name
or to_s
to the name it is bound to, very early on. That way, we would be able to address return values or the use of type variables inside other generic types as well. (I assume the current implementation does not support something like sig { params(foo: T::Array[Elem]).void }
either)
@paracycle how would you go about binding it? The return of |
I see two ways to do that:
|
Hmm, I see now that option 2 is not that straightforward since we store |
@paracycle the latest commit includes the process you mentioned. Let me know if that's what you had in mind. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is very close and the output is already much better. I see that we've already caught a T::Struct
prop type as well. I left some comments to make this work even better.
Also, can we add a few test cases where the generic type variables are nested in some other type, like T::Hash[T::Array[Template], T::Set[Elem]]
kind of thing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great. Thank you!
Closes #323
Motivation
The current mechanism for compiling signature types is by invoking
to_s
on the specific constant used for the type. However, generics always returnT.untyped
for theto_s
, so we need an alternative mechanism to get the actual constant name for compilation.Note:
constant.name
also returnsT.untyped
.Implementation
Basically, it boils down to this:
Tests
I added an extra
type_template
, since those also need special care when compiling.