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

Merge nested polytypes in more cases in resolveOverloaded #15636

Merged
merged 1 commit into from
Jul 10, 2022

Conversation

griggt
Copy link
Contributor

@griggt griggt commented Jul 9, 2022

In some cases while going deeper into alternatives during overload resolution,
we may end up with a nested polytype after dropping contextual parameters.

In particular this can happen for an extension with a using clause, as seen
in tests/pos/i11713.scala and tests/pos/i13668.scala.

The overload applicability test fails here unless the type parameter lists
are merged.

Co-authored-by: Gagandeep Kalra gagandeepkalra1994@gmail.com
Co-authored-by: Mark T. Kennedy mtk@acm.org

Fixes #11713
Fixes #13668

In some cases while going deeper into alternatives during overload resolution,
we may end up with a nested polytype after dropping contextual parameters.

In particular this can happen for an extension with a `using` clause, as seen
in tests/pos/i11713.scala and tests/pos/i13668.scala.

The overload applicability test fails here unless the type parameter lists
are merged.

Co-authored-by: Gagandeep Kalra <gagandeepkalra1994@gmail.com>
Co-authored-by: Mark T. Kennedy <mtk@acm.org>

Fixes scala#11713
Fixes scala#13668
@griggt
Copy link
Contributor Author

griggt commented Jul 9, 2022

Before this PR, we could see these failures in overload resolution:

[... snip ...]
resolve mapped: [T1](using x$2: Numeric[T1])(y: String): Nothing, [T1](using x$2: Numeric[T1]): [T2](y: T2)(using x$4: Numeric[T2]): Nothing with [applied to (200) returning ?]
resolve mapped: [T1](y: String): Nothing, [T1] => [T2](y: T2)(using x$4: Numeric[T2]): Nothing with [applied to (200) returning ?]
narrowed by size: def combine[T1](y: String): Nothing, def combine[T1]: [T2](y: T2)(using x$4: Numeric[T2]): Nothing
narrowed by shape: def combine[T1](y: String): Nothing, def combine[T1]: [T2](y: T2)(using x$4: Numeric[T2]): Nothing
narrowed by size: def combine[T1](y: String): Nothing, def combine[T1]: [T2](y: T2)(using x$4: Numeric[T2]): Nothing
narrowed by shape: def combine[T1](y: String): Nothing, def combine[T1]: [T2](y: T2)(using x$4: Numeric[T2]): Nothing
-- [E008] Not Found Error: tests/pending/i11713.scala:5:14 ---------------------
5 |val res = 100.combine(200)
  |          ^^^^^^^^^^^
  |      value combine is not a member of Int.
  |      An extension method was tried, but could not be fully constructed:
  |
  |          combine()    failed with
  |
  |              value combine: <overloaded combine> does not take parameters
[... snip ...]
resolve mapped: [L](using x$2: Candidate[L])(rhs: Bear): Unit, [L](using x$2: Candidate[L]): [RW](rhs: Fuzzy[RW]): Unit with [applied to (Fuzzy[1.type]()) returning ?]
resolve mapped: [L](rhs: Bear): Unit, [L] => [RW](rhs: Fuzzy[RW]): Unit with [applied to (Fuzzy[1.type]()) returning ?]
narrowed by size: def +[L](rhs: Bear): Unit, def +[L]: [RW](rhs: Fuzzy[RW]): Unit
narrowed by shape: def +[L](rhs: Bear): Unit, def +[L]: [RW](rhs: Fuzzy[RW]): Unit
narrowed by size: def +[L](rhs: Bear): Unit, def +[L]: [RW](rhs: Fuzzy[RW]): Unit
narrowed by shape: def +[L](rhs: Bear): Unit, def +[L]: [RW](rhs: Fuzzy[RW]): Unit
-- [E008] Not Found Error: tests/pending/i13668.scala:15:21 --------------------
15 |val fails = MyType() + Fuzzy[1]()
   |            ^^^^^^^^^^
   |      value + is not a member of MyType.
   |      An extension method was tried, but could not be fully constructed:
   |
   |          +()    failed with
   |
   |              value +: <overloaded +> does not take parameters

@griggt griggt requested a review from odersky July 9, 2022 22:04
Copy link
Contributor

@odersky odersky left a comment

Choose a reason for hiding this comment

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

A one line change fixes two issues. Nice!

@odersky odersky merged commit 79d9a6f into scala:main Jul 10, 2022
@griggt griggt deleted the fix-13668 branch July 10, 2022 08:14
@Kordyjan Kordyjan added this to the 3.2.1 milestone Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants