You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
because the typer infers that the type of variable a (not the type of the object variable a refers to) is Superclass, because after the second invocation, it is clear that it cannot be Subclass, else the Superclass result could not be stored in the variable.
Unfortunately, the current mirah compiler does not produce either of these results.
I'd like you (@headius, @baroquebobcat, @uujava, and everyone else) to suggest what should be the correct output, and it would be nice if you could explain why.
In my opinion, when forced to decide whether to give up widening of types of local variables or to give up attaching macros to types, I would give up widening of types of local variables. Hence, the code above would be invalid, but
classTestdefruna=Superclass(Subclass.new)# cast to make the type of a clear right from the outsetb=0whileb < 2a=a.fooa=a.fooa=a.foob+=1endendend
would be valid.
This decision would also allow to remove the speculative type guessing at
which may considerably speed up the compilation time. This in turn would allow the type inference to behave monotonously (instead of the current non-monotonous behavior, where the inferred type can be changed after it has been consumed). This in turn would allow to solve #421 by invoking a macro only when type it is attached to has been determined definitely. This in turn would allow to solve #420 by supplying an argument to a macro only once that argument's type has been determined definitely, and using that argument directly instead of a ProxyNode.
The text was updated successfully, but these errors were encountered:
This is a tricky edge case.
Removing widening would have a lot of far reaching implications because it will dramatically increase the number of required type annotations. I would really prefer not to do that.
How about this:
If a variable being widened would change the lookup result for a macro that had been called on it, raise an error asking for type clarification.
That would make your first example invalid, but would allow for cases where the macro calls widen a type benignly. It would also not require backtracking.
Mirah has 2 distinct features:
Unfortunately, they are incompatible with each other.
Consider this MIrah code:
What is the expected output of this code?
It could be
because the calls to method
foo
alternate.It could also be
because the typer infers that the type of variable
a
(not the type of the object variable a refers to) isSuperclass
, because after the second invocation, it is clear that it cannot beSubclass
, else theSuperclass
result could not be stored in the variable.Unfortunately, the current mirah compiler does not produce either of these results.
I'd like you (@headius, @baroquebobcat, @uujava, and everyone else) to suggest what should be the correct output, and it would be nice if you could explain why.
In my opinion, when forced to decide whether to give up widening of types of local variables or to give up attaching macros to types, I would give up widening of types of local variables. Hence, the code above would be invalid, but
would be valid.
This decision would also allow to remove the speculative type guessing at
mirah/src/org/mirah/typer/assignable_type_future.mirah
Line 183 in 1c49718
The text was updated successfully, but these errors were encountered: