Repository navigation
New generics: a static class sees the enclosing class's parameter as its own variable - #1424
Merged
Merged
Conversation
…its own variable
A static class inside a generic class (class Outer<T:> with static class
Holder) has a type variable of its own for T, but did not use it
consistently, so Jass failed to compile in several shapes which Lua
accepted:
- a member of the static class was translated with the type variables of
whatever code first asked for it: a method Outer calls took and returned
Outer's T while its body used the static class's ("Type variable T not
eliminated"), and the same for fields, constructors and closures;
- a type of the static class had no argument for that variable, so
C extends Base gave C the superclass Base<> ("Rewrite generics with
wrong sizes");
- a static function of the static class, which is not in its class, used
the class's variable, which it does not have.
The members of a class are now translated with the class's type variables
whoever asks for them first, and the type of this is the class with its
own variables. A type of a static class carries an argument for its
variable: what the type binds it to (new Outer<int>().make() returns a
Base with T bound to int), or else the parameter as the code sees it,
Outer's own in Outer and the captured one in the static class. Super
constructor and ondestroy calls pass it, and a static function of a static
class takes it as a type variable of its own, as a static function of the
generic class does. EliminateGenerics no longer fills in missing type
arguments by name.
The function a class gets for an inherited interface implementation
translates the superclass's type arguments the same way, with the class's
variables, so a static class implementing an interface with an inherited
method over T is dispatched on Jass too.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #1423 (base
generic-interface-bridge). Merge this one into #1423's branch before #1423 is merged, or a roll-up PR to master follows.Problem
A static class inside a generic class (
class Outer<T:>withstatic class Holder) gets a type variable of its own forT. The translator did not use it consistently. Lua accepted these programs, but Jass failed to compile them:Outercalls took and returnedOuter'sT, while its body used the static class's own variable. The error wasType variable T not eliminated. Fields, constructors, ondestroy blocks and closures failed the same way.C extends BasegaveCthe superclassBase<>. The error wasRewrite generics with wrong sizes. The same happened with or without an interface. This is why Interface bridge: give generic classes a method of their own too #1423's static-class test ran on Lua only.Change
Members. A class's members (methods, constructors, ondestroy, fields) are now translated with the class's own type variables, whichever code asks for them first. In a static class, these include the captured variable. The type of
thisis the class with its own variables, and the class's variables no longer depend on where it is first used.Types. A type of a static class carries an argument for its captured variable. The argument is one of two things:
new Outer<int>().make()returns aBasewithTbound toint;Outer's own variable insideOuter, and the captured one inside the static class.This means
C extends Basenow givesCthe superclassBase<T_C>. Super constructor and ondestroy calls pass the argument along.Static functions. A static function of a static class takes the captured parameter as a type variable of its own, as a static function of the generic class already does.
Removed patch.
EliminateGenericsno longer fills in missing class type arguments by matching type-variable names. Nothing produces the short types any more.Interface bridge (#1423).
typeArgumentsAsSeenFromnow translates the superclass's type as the class's own functions do, with the class's type variables. A static class that implements an interface through an inherited method overTis now dispatched on Jass too.Checks
New tests: nine
GenericsWithTypeclassesTestsand oneInterfaceTestscase, each running Jass, the interpreter and Lua. They cover:T;T;All of them failed on Interface bridge: give generic classes a method of their own too #1423's head (Jass), as did Interface bridge: give generic classes a method of their own too #1423's static-class test, which now runs on Jass too.
Determinism: a new
DeterministicCheckscase puts the interface in its own package and compiles in both unit orders. The Jass and Lua are identical.Test classes: these 23 pass (1,407 tests): the 23 classes Interface bridge: give generic classes a method of their own too #1423 lists, including
GenericsWithTypeclassesTests,GenericsTests,ClassesTests,InterfaceTests,DeterministicChecksandBugTests.Real maps: castle fight and zombie defense, built with
-lua -inline -localOptimizations, produce Lua byte-identical to Interface bridge: give generic classes a method of their own too #1423's head.