flix icon indicating copy to clipboard operation
flix copied to clipboard

feat: check import return type

Open paulbutcher opened this issue 3 years ago • 8 comments

This PR is draft because definitely not yet complete. But I need some advice as to how to proceed from here.

I've plumbed the return type through the AST to the resolver. The check on this line is clearly wrong, but I'm not sure what the right way to check that the declared return value matches the method is?

https://github.com/paulbutcher/flix/blob/import-retval/main/src/ca/uwaterloo/flix/language/phase/Resolver.scala#L2507

Also not done yet: the same functionality for constructors and field access.

paulbutcher avatar Jul 30 '22 11:07 paulbutcher

Looks ok to me, but lets ask @mlutze if he agrees.

magnus-madsen avatar Jul 30 '22 19:07 magnus-madsen

Looks ok to me, but lets ask @mlutze if he agrees.

Well, it causes (as you can see!) plenty of failed tests, so I assume that there's a better approach...

paulbutcher avatar Jul 30 '22 19:07 paulbutcher

It should at least be a subtype check, I guess. But more seems to be wrong than that?

magnus-madsen avatar Jul 30 '22 19:07 magnus-madsen

We're importing methods that return arrays with regions. A normal (regionless) array is Array[a, Static] so even a subtype check would be insufficient because Static is not a subtype of r: Region.

I'm not sure what the best solution is. In principle, we ought not to allow import XYZ: Array[Int32, r], but it seems like a very convenient feature.

mlutze avatar Jul 30 '22 19:07 mlutze

Ah- I did not think of that complication.

magnus-madsen avatar Jul 30 '22 19:07 magnus-madsen

Until I understand regions properly (which I currently don't), I think I need to rely on one of you to tell me what the right way forwards is here?

paulbutcher avatar Jul 30 '22 19:07 paulbutcher

Lets be practical and incremental. How about we start by doing the check for: (1) any primitive type and (2) any Java type. For all other types (arrays, enums, other Flix types) we skip the check. Once this works, we can think deeper about it or defer, since we will catch most issues anyway.

magnus-madsen avatar Aug 03 '22 18:08 magnus-madsen

We can add the more advanced checks once we have actually figured out how to integrate (1) generics, (2) regions, (3) effects, (4) function types with Java. For now a 90% solution seems like a great improvement.

magnus-madsen avatar Aug 03 '22 19:08 magnus-madsen

This is now ready to be merged, I think.

paulbutcher avatar Aug 31 '22 09:08 paulbutcher

Merged! Thanks

magnus-madsen avatar Aug 31 '22 11:08 magnus-madsen

Fixes #4395

paulbutcher avatar Aug 31 '22 11:08 paulbutcher