Skip to content

Commit 972450d

Browse files
Merge pull request #7943 from dotty-staging/fix-#6503
Fix #6503: Handle dependent refinements
2 parents 061dc96 + 5866066 commit 972450d

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

compiler/src/dotty/tools/dotc/typer/ErrorReporting.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ object ErrorReporting {
167167
*/
168168
def userDefinedErrorString(raw: String, paramNames: List[String], args: List[Type]): String = {
169169
def translate(name: String): Option[String] = {
170+
assert(paramNames.length == args.length)
170171
val idx = paramNames.indexOf(name)
171172
if (idx >= 0) Some(quoteReplacement(ex"${args(idx)}")) else None
172173
}

compiler/src/dotty/tools/dotc/typer/Implicits.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1217,7 +1217,7 @@ trait Implicits { self: Typer =>
12171217
err.userDefinedErrorString(
12181218
raw,
12191219
pt.typeSymbol.typeParams.map(_.name.unexpandedName.toString),
1220-
pt.widenExpr.argInfos))
1220+
pt.widenExpr.dropDependentRefinement.argInfos))
12211221

12221222
def hiddenImplicitsAddendum: String =
12231223

tests/neg/i6503.scala

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
trait MapImpl {
2+
type Key
3+
type Value
4+
type Map
5+
val lookup: Map => Key => Value
6+
}
7+
import scala.collection.immutable.HashMap
8+
9+
class HashMapImpl[K, V] extends MapImpl {
10+
type Key = K
11+
type Value = V
12+
type Map = HashMap[K, V]
13+
val lookup: Map => Key => Value = m => k => m(k)
14+
}
15+
16+
object Foo {
17+
val Server0:
18+
(mImpl: MapImpl) => mImpl.Map => mImpl.Key => mImpl.Value
19+
= mImpl => mImpl.lookup
20+
val Client:
21+
(server: (mImpl: MapImpl { type Key = String; type Value = Int}) => mImpl.Map => String => Int) => Int =
22+
server => server(HashMapImpl[String, Int])(HashMap())("test lookup key")
23+
val Client1:
24+
(server: (mImpl: MapImpl { type Key = String; type Value = Int}) => mImpl.Map => String => Int) => Int =
25+
server => server(??? : (HashMapImpl[String, Int]))(???)("test lookup key")
26+
val Client2:
27+
(server: (mImpl: MapImpl { type Key = String; type Value = Int}) => mImpl.Map => String => Int) => Int =
28+
server => server(???)(???)("test lookup key")
29+
val Server1: (mImpl: MapImpl {type Key = String; type Value = Int}) => mImpl.Map => String => Int =
30+
mImpl => Server0(mImpl)
31+
implicitly[(mImpl: MapImpl {type Key = String; type Value = Int}) => mImpl.Map => String => Int <:< (mImpl: MapImpl) => mImpl.Map => mImpl.Key => mImpl.Value] // error
32+
implicitly[(mImpl: MapImpl {type Key = String; type Value = Int}) => mImpl.Map => mImpl.Key => mImpl.Value <:< (mImpl: MapImpl) => mImpl.Map => mImpl.Key => mImpl.Value] // error
33+
34+
val Result1: Int = Client(Server0) // error
35+
val Result2: Int = Client(Server1)
36+
val Result3: Int = Client(mImpl => Server0(mImpl))
37+
}

0 commit comments

Comments
 (0)