A rule to make typing nested classes more flexible #14390
Replies: 1 comment
-
|
I meditated a bit on this example and now I'm no longer sure why does it matter that EDIT: ok, let me be a bit more explicit. If I look at the example, I already see |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
#14387 can replace some of #13657 but not all. For instance, the following would still require #13657 to be able to typecheck
tail:But we can hopefully get on safer ground by adding an alternative rule. The idea is that the local class
Mappedsees the outer referencesfandxsthroughthis. You could imagine a meaning preserving transformation wherefandxsare cached in additional fields of classMappedlike this:and every reference to
forxsis replaced bythis.this_fandthis.this_xs.Let's now compare the expression
xs.tail.map(f)of type{f, xs} LazyList[B]with the expected type{this} LazyList[B]. Since there are no tracked parameters enclosing the expression inside classMapped, every occurrence offorxsin the capture setCmust have come throughthis, so we can equivalently usethis.this_fandthis.this_xs, which are both subsumed bythis. In other words, to compare actual{f, xs}with expected{this}, we can ignore any reference in the actual capture set that goes to a variable defined outsideMapped, so bothfandxsare discarded and the check succeeds.More generally: When checking an expression
e: Ca Taagainst an expected typeCx Txwhere the capture set ofCxcontainsthisand any method inside the classClsofthisthat containsehas only pure parameters, drop fromCaall references to variables orthisreferences outsideCls. These are all accessed throughthis, so are already accounted for byCx.Beta Was this translation helpful? Give feedback.
All reactions