Skip to content

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

Closed
@smarter

Description

@smarter

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions