-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Initial support for aliases. #1262
Conversation
@@ -2169,6 +2169,72 @@ auto TypeChecker::TypeCheckChoiceDeclaration( | |||
return Success(); | |||
} | |||
|
|||
static bool IsValidAliasTarget(Nonnull<const Value*> type) { |
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 is actually checking the type of the alias target, not the alias target itself. This nuance is a little misleading for the alias x = i32
case where I'd say the target is i32
, not type(i32)
, but this gets called with type(i32)
. Maybe rename+comment the function, maybe IsValidAliasType
or CanAliasType
?
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.
Renamed.
|
||
package ExplorerTest api; | ||
|
||
alias TypeAlias = i32; |
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.
Can you switch most of these to separate files? This setup is okay when everything's passing, but if something breaks, it'd be easier to figure out what's broken with smaller tests.
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.
Done.
Co-authored-by: Jon Meow <[email protected]>
var c: GenericClass(i32) = {}; | ||
var d: GenericClassAlias(i32) = c; | ||
var e: ClassSpecializationAlias = c; | ||
return 0; |
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.
FWIW, you might want to put a variable on your classes and return the result or something, to verify that data is tracked properly with an alias. In another test you did:
class Class { var a: i32; }
class GenericClass(T:! Type) { var a: T; }
That's really all I'm suggesting here.
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.
Done.
fn Main() -> i32 { | ||
var ab: AB = {.b = 1, .a = 2}; | ||
var ba: BA = ab; | ||
return 1000 * ab.a + 100 * ab.b + 10 * ba.a + ba.b; |
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.
Maybe drop TODOs on these to use print()
if we can get that supporting ints in output?
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.
Done.
This supports aliases for types (including interfaces), functions, parameterized types, instance member names, and interface member names. Co-authored-by: Jon Meow <[email protected]>
This supports aliases for types (including interfaces), functions, parameterized types, instance member names, and interface member names.