-
Notifications
You must be signed in to change notification settings - Fork 12
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
fe: infer result type of redef
via redefined feature
#4023
base: main
Are you sure you want to change the base?
fe: infer result type of redef
via redefined feature
#4023
Conversation
74701ea
to
3b3216c
Compare
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.
Nice.
I have some suggestions how to get this to work with type parameters and this type and some improvements.
say c.b | ||
say c.d |
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.
say c.b | |
say c.d | |
say c.b | |
say c.d | |
say (type_of c.b) | |
say (type_of c.d) |
a is | ||
b option String => "String" | ||
d => option "String" | ||
# NYI: UNDER DEVELOPEMENT result type with generic argument / this 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.
Would be good to add examples that do not work yet to this comment.
{ | ||
AbstractType t = null; | ||
var it = redefines().iterator(); | ||
while(t == null && it.hasNext()) |
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.
while(t == null && it.hasNext()) | |
while (t == null && it.hasNext()) |
{ | ||
t = f.returnType().functionReturnType(); | ||
} | ||
else if (!redefines().isEmpty()) |
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 always true
{ | ||
var redefined = it.next(); | ||
if (!(_returnType instanceof FunctionReturnType) | ||
&& !redefines().isEmpty() |
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 always true
@@ -2183,7 +2183,16 @@ else if (_impl.typeInferable()) | |||
{ | |||
if (CHECKS) check | |||
(!state().atLeast(State.TYPES_INFERENCED)); | |||
result = _impl.inferredType(res, this, urgent); | |||
var t = resultTypeFromRedefined(res); | |||
// NYI: UNDER DEVELOPMENT: handle types that contain generic arguments / this types. |
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.
What is missing here is a call to handDownNonOpen(res, t, featureThatIsRedefined)
, then the generics and this types should be adjusted accordingly.
/** | ||
* Does this type contain a generic argument? | ||
* | ||
* @return | ||
*/ | ||
public boolean containsGenericArgument() | ||
{ | ||
return isGenericArgument() | ||
|| !isGenericArgument() && (generics().stream().anyMatch(g -> g.containsGenericArgument()) || | ||
outer() != null && outer().containsGenericArgument()); | ||
} | ||
|
||
|
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.
Use dependsOnGenerics
instead.
&& redefined instanceof Feature f | ||
&& f.returnType() instanceof FunctionReturnType) | ||
{ | ||
t = f.returnType().functionReturnType(); |
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 it would be better to use the code in the else branch in this case as well, i.e., resolveTypes
and resultTypeIfPresent
.
# ----------------------------------------------------------------------- | ||
|
||
infer_result_type_via_redefined => | ||
|
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 am missing some test cases:
- redefining two or more inherited features with equal types
- redefining result types
a
andb
asvoid
- redefining
a.f unit
,b.f void
,c.f String
inshould IMHO work.a is f unit => b is f => do c is f => "hi" d : a, b, c is redef f => panic "bla"
- negative tests
Does not work yet if result type contains a generic argument or this type.