-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #401: Avoid asSeenFrom for types/bounds that don't depend on the …
…prefix. This mostly acts as a fast path. However, for the particular case of static recursive match types, it more critically cuts some infinite recursion. Normally, when a match type refers to itself, it would do so through a `ThisType`. Computing `asSeenFrom` for a `ThisType` prefix already cuts the infinite recursion because it is, by construction, a no-op. However, for static recursive match types, the compiler makes them refer to themselves through their public, static prefix. This caused the infinite recursion observed in #401. To avoid the issue, we use another shortcut to `asSeenFrom`: if the type we map over does not contain any `ThisType`, we also know it will be a no-op. We store that as a lazy val `isPrefixDependent` of `TermSymbol` and `TypeMemberSymbol`, so that they can take a short cut in `{type,bounds}AsSeenFrom`.
- Loading branch information
Showing
5 changed files
with
112 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
18 changes: 18 additions & 0 deletions
18
test-sources/src/main/scala/simple_trees/RecursiveMatchType.scala
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package simple_trees | ||
|
||
type RecursiveMatchType[A <: Tuple] <: Tuple = A match | ||
case hd *: tl => hd *: RecursiveMatchType[tl] | ||
case EmptyTuple => EmptyTuple | ||
|
||
object RecursiveMatchType: | ||
inline def rec[A <: Tuple](a: A): RecursiveMatchType[A] = | ||
inline a match | ||
case b: (hd *: tl) => b.head *: rec(b.tail) | ||
case _: EmptyTuple => EmptyTuple | ||
end RecursiveMatchType | ||
|
||
// must be in a separate TASTy file to trigger issue #401 | ||
object RecursiveMatchTypeTest: | ||
inline def rec[A <: Tuple](x: A): RecursiveMatchType[A] = | ||
RecursiveMatchType.rec(x) | ||
end RecursiveMatchTypeTest |