Skip to content

Regression in 3.7.1-RC1: type error when calling dependent method despite types matching #23217

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

Closed
smarter opened this issue May 21, 2025 · 0 comments · Fixed by #23226
Closed
Assignees
Labels
area:typer itype:bug regression This worked in a previous version but doesn't anymore

Comments

@smarter
Copy link
Member

smarter commented May 21, 2025

Compiler version

Regression started with #22839 present in 3.7.1-RC1.

Minimized code

//> using scala 3.7.1-RC1

trait HasA[T]:
  type A = T

object Test1:
  def foo1(h: HasA[?])(a: h.A): Unit = {}

  def foo2(h1: HasA[?])(a1: h1.A): Unit =
    foo1(h1)(a1) // ok

  def foo3(h1: HasA[?], a1: h.A): Unit =
    foo1(h1)(a1) // ok

object Test2:
  def bar1(h: HasA[?], a: h.A): Unit = {}

  def bar2(h1: HasA[?], a1: h1.A): Unit =
    bar1(h1, a1) // error

  def foo3(h1: HasA[?])(a1: h1.A): Unit =
    bar2(h1, a1) // error

Output

-- [E007] Type Mismatch Error: try/inew.scala:17:13 ----------------------------
17 |    bar1(h1, a1) // error
   |             ^^
   |Found:    (a1 : h1.A)
   |Required: h.A
   |Note that implicit conversions were not tried because the result of an implicit conversion
   |must be more specific than h.A
   |----------------------------------------------------------------------------
   | Explanation (enabled by `-explain`)
   |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   |
   | Tree: a1
   | I tried to show that
   |   (a1 : h1.A)
   | conforms to
   |   h.A
   | but none of the attempts shown below succeeded:
   |
   |   ==> (a1 : h1.A)  <:  h.A
   |     ==> (a1 : h1.A)  <:  T
   |       ==> h1.A  <:  T
   |         ==> h1.T  <:  T
   |           ==> (h1 : HasA[?])  <:  (HasA.this : HasA[T])
   |             ==> HasA[?]  <:  (HasA.this : HasA[T])  = false
   |           ==> Any  <:  T  = false
   |
   | The tests were made under the empty constraint
    ----------------------------------------------------------------------------
-- [E007] Type Mismatch Error: try/inew.scala:20:13 ----------------------------
20 |    bar2(h1, a1) // error
   |             ^^
   |Found:    (a1 : h1.A)
   |Required: h1².A
   |
   |where:    h1  is a parameter in method foo3
   |          h1² is a reference to a value parameter
   |
   |Note that implicit conversions were not tried because the result of an implicit conversion
   |must be more specific than h1.A
   |----------------------------------------------------------------------------
   | Explanation (enabled by `-explain`)
   |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   |
   | Tree: a1
   | I tried to show that
   |   (a1 : h1.A)
   | conforms to
   |   h1.A
   | but none of the attempts shown below succeeded:
   |
   |   ==> (a1 : h1.A)  <:  h1.A
   |     ==> (a1 : h1.A)  <:  T
   |       ==> h1.A  <:  T
   |         ==> h1.T  <:  T
   |           ==> (h1 : HasA[?])  <:  (HasA.this : HasA[T])
   |             ==> HasA[?]  <:  (HasA.this : HasA[T])  = false
   |           ==> Any  <:  T  = false
   |
   | The tests were made under the empty constraint
    ----------------------------------------------------------------------------

Expectation

No error, like in 3.7.0 and previous versions. The errors go away if I turn off the changes from #22839 :

diff --git compiler/src/dotty/tools/dotc/core/Types.scala compiler/src/dotty/tools/dotc/core/Types.scala
index c2c508dc27..971225bc28 100644
--- compiler/src/dotty/tools/dotc/core/Types.scala
+++ compiler/src/dotty/tools/dotc/core/Types.scala
@@ -3822,7 +3822,7 @@ object Types extends TypeUtils {
     def integrate(tparams: List[ParamInfo], tp: Type)(using Context): Type =
       (tparams: @unchecked) match {
         case LambdaParam(lam, _) :: _ => tp.subst(lam, this) // This is where the precondition is necessary.
-        case params: List[Symbol @unchecked] => IntegrateMap(params, paramRefs)(tp)
+        case params: List[Symbol @unchecked] => tp.subst(params, paramRefs)
       }

     /** A map that replaces references to symbols in `params` by the types in
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:typer itype:bug regression This worked in a previous version but doesn't anymore
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants