Skip to content
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

Fix #423: Merge the TypeBounds of type members without needing subtyping. #427

Merged
merged 1 commit into from
Dec 19, 2023

Conversation

sjrd
Copy link
Contributor

@sjrd sjrd commented Dec 18, 2023

There was an infinite recursion between looking up a type member of a refinement and subtyping of that member against the same refinement. This came from computing the merged TypeBounds of the type member during subtyping, which used subtyping to get rid of useless bounds.

We break the cycle by not using subtyping when merging the TypeBounds of a type member anymore. Instead, we manually dive into possibly-higher-kinded bounds (TypeLambdas themselves, but also Nothing and AnyKind), and otherwise construction a union or intersection type.

Unwrapping higher-kinded bounds is necessary because constructing a uniont or intersection requires proper types.


I did not manage to come up with an isolated reproduction, unfortunately. But with the dependency in #423, I can now successfully run the following test:

  testWithContext("issue-423") {
    val FlowOpsClass = ctx.findTopLevelClass("akka.stream.scaladsl.FlowOps")

    val groupBy = FlowOpsClass.findAllOverloadedDecls(termName("groupBy")).find {
      groupBy => groupBy.paramSymss.map(_.merge.size).sum == 4
    }.get
    println(groupBy.tree.get.showMultiline)

    val select = findTree(groupBy.tree.get) {
      case select @ Select(_, SignedName(SimpleName("via"), _, _)) => select
    }
    println(select.showBasic)
    println(select.symbol)
  }

@sjrd sjrd requested a review from adpi2 December 18, 2023 14:54
…ding subtyping.

There was an infinite recursion between looking up a type member
of a refinement and subtyping of that member against the same
refinement. This came from computing the merged TypeBounds of the
type member during subtyping, which used subtyping to get rid of
useless bounds.

We break the cycle by not using subtyping when merging the
TypeBounds of a type member anymore. Instead, we manually dive into
possibly-higher-kinded bounds (`TypeLambda`s themselves, but also
`Nothing` and `AnyKind`), and otherwise construction a union or
intersection type.

Unwrapping higher-kinded bounds is necessary because constructing
a uniont or intersection requires proper types.
Copy link
Member

@adpi2 adpi2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It passes my test and does not break anything else

@sjrd sjrd merged commit 0f86044 into scalacenter:main Dec 19, 2023
4 checks passed
@sjrd sjrd deleted the fix-issue-423 branch December 19, 2023 15:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants