Skip to content

Commit 90cb5c4

Browse files
committed
WIP
1 parent fe27659 commit 90cb5c4

File tree

8 files changed

+54
-26
lines changed

8 files changed

+54
-26
lines changed

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,6 +1001,7 @@ trait Implicits:
10011001
val ref = cand.ref
10021002
val generated: Tree = tpd.ref(ref).withSpan(span.startPos)
10031003
val locked = ctx.typerState.ownedVars
1004+
var misMatch = false
10041005
val adapted =
10051006
if (argument.isEmpty)
10061007
adapt(generated, pt.widenExpr, locked)
@@ -1016,9 +1017,14 @@ trait Implicits:
10161017
locked)),
10171018
nme.apply)
10181019
else untpdGenerated
1019-
typed(
1020+
val converted = typed(
10201021
untpd.Apply(untpdConv, untpd.TypedSplice(argument) :: Nil),
10211022
pt, locked)
1023+
pt match
1024+
case selProto: SelectionProto if !selProto.isMatchedBy(converted.tpe) =>
1025+
misMatch = true
1026+
case _ =>
1027+
converted
10221028
}
10231029
pt match
10241030
case selProto @ SelectionProto(selName: TermName, mbrType, _, _) if cand.isExtension =>
@@ -1040,7 +1046,8 @@ trait Implicits:
10401046
case _ =>
10411047
tryConversion
10421048
}
1043-
if ctx.reporter.hasErrors
1049+
if misMatch
1050+
|| ctx.reporter.hasErrors
10441051
|| !cand.ref.symbol.isAccessibleFrom(cand.ref.prefix)
10451052
then
10461053
ctx.reporter.removeBufferedMessages

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

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,9 @@ class Typer extends Namer
537537
errorTree(tree, MissingIdent(tree, kind, name))
538538
end typedIdent
539539

540+
val newScheme: Boolean = true
541+
val dia: Boolean = false
542+
540543
/** Check that a stable identifier pattern is indeed stable (SLS 8.1.5)
541544
*/
542545
private def checkStableIdentPattern(tree: Tree, pt: Type)(using Context): Unit =
@@ -566,12 +569,26 @@ class Typer extends Namer
566569
else if couldInstantiateTypeVar(qual.tpe.widen) then
567570
// try again with more defined qualifier type
568571
typedSelect(tree, pt, qual)
569-
else if qual.tpe.derivesFrom(defn.DynamicClass)
570-
&& selName.isTermName && !isDynamicExpansion(tree)
571-
then
572-
if pt.isInstanceOf[FunOrPolyProto] || pt == AssignProto then finalize(TryDynamicCallType)
573-
else typedDynamicSelect(tree0, Nil, pt)
574572
else
573+
val tree1 =
574+
if newScheme then
575+
if dia then println(i"tryec $qual . $selName\n, pt = $pt\n, mbrProto = ${IgnoredProto(pt)}\n, compat = ${this.getClass}, locked = ${ctx.typerState.ownedVars.toList}%, %?")
576+
tryExtensionOrConversion(
577+
tree, pt, IgnoredProto(pt), qual, ctx.typerState.ownedVars, this, privateOK = true)
578+
else EmptyTree
579+
if newScheme && dia then
580+
println(i"tryec $qual . $selName\n, pt = $pt\n, mbrProto = ${IgnoredProto(pt)}\n, compat = ${this.getClass}, locked = ${ctx.typerState.ownedVars.toList}%, % = $tree1")
581+
if !tree1.isEmpty then
582+
tree1
583+
// else if couldInstantiateTypeVar(qual.tpe.widen) then
584+
// // try again with more defined qualifier type
585+
// typedSelect(tree, pt, qual)
586+
else if qual.tpe.derivesFrom(defn.DynamicClass)
587+
&& selName.isTermName && !isDynamicExpansion(tree)
588+
then
589+
if pt.isInstanceOf[FunOrPolyProto] || pt == AssignProto then finalize(TryDynamicCallType)
590+
else typedDynamicSelect(tree0, Nil, pt)
591+
else
575592
finalize(
576593
rawType match
577594
case rawType: NamedType =>
@@ -2950,6 +2967,7 @@ class Typer extends Namer
29502967
if ctx.mode.is(Mode.ImplicitsEnabled) && qual.tpe.isValueType then
29512968
trace(i"try insert impl on qualifier $tree $pt") {
29522969
val selProto = selectionProto
2970+
//println(i"try conv $tree, $qual, ${qual.tpe}, $selProto, ${inferView(qual, selProto)}")
29532971
inferView(qual, selProto) match
29542972
case SearchSuccess(found: ExtMethodApply, _, _) =>
29552973
return found.app // nothing to check or adapt for extension method applications
@@ -3573,6 +3591,12 @@ class Typer extends Namer
35733591
case _ => ;
35743592
}
35753593

3594+
pt match
3595+
case selProto @ SelectionProto(selName: TermName, mbrType, _, _) =>
3596+
if newScheme then return tree
3597+
else if dia then println(i"tryec $tree, $tree . $selName\n, pt = ${mbrType.deepenProto}\n, mbrProto = $mbrType\n, compat = ${selProto.compat.getClass}, locked = ${locked.toList}%, %, privateOK = ${selProto.privateOK}")
3598+
case _ =>
3599+
35763600
// try an extension method in scope
35773601
pt match {
35783602
case selProto @ SelectionProto(selName: TermName, mbrType, _, _) =>
@@ -3610,6 +3634,7 @@ class Typer extends Namer
36103634
|| pt.isRef(defn.ObjectClass, skipRefined = false)
36113635
then
36123636
report.error(em"the result of an implicit conversion must be more specific than $pt", tree.srcPos)
3637+
//println(i"try view $tree, ${tree.tpe}, $pt, ${inferView(tree, pt)}")
36133638
inferView(tree, pt) match {
36143639
case SearchSuccess(found: ExtMethodApply, _, _) =>
36153640
found // nothing to check or adapt for extension method applications

tests/neg/enum-values.check

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
|
2121
| example.Extensions.values(ListLike) failed with
2222
|
23-
| Found: example.ListLike.type
24-
| Required: Nothing
23+
| Found: Array[example.Tag[?]]
24+
| Required: Array[example.ListLike[?]]
2525
-- [E008] Not Found Error: tests/neg/enum-values.scala:34:52 -----------------------------------------------------------
2626
34 | val typeCtorsK: Array[TypeCtorsK[?]] = TypeCtorsK.values // error
2727
| ^^^^^^^^^^^^^^^^^
@@ -32,8 +32,8 @@
3232
|
3333
| example.Extensions.values(TypeCtorsK) failed with
3434
|
35-
| Found: example.TypeCtorsK.type
36-
| Required: Nothing
35+
| Found: Array[example.Tag[?]]
36+
| Required: Array[example.TypeCtorsK[?[_$1]]]
3737
-- [E008] Not Found Error: tests/neg/enum-values.scala:36:6 ------------------------------------------------------------
3838
36 | Tag.valueOf("Int") // error
3939
| ^^^^^^^^^^^

tests/neg/i6779.check

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,16 @@
33
| ^^^^^^^^^^^^^^^^^^^^^^^^
44
| Found: F[T]
55
| Required: F[G[T]]
6-
-- [E007] Type Mismatch Error: tests/neg/i6779.scala:12:31 -------------------------------------------------------------
6+
-- [E008] Not Found Error: tests/neg/i6779.scala:12:31 -----------------------------------------------------------------
77
12 | def g2[T](x: T): F[G[T]] = x.f // error
88
| ^^^
9-
| Found: F[T]
10-
| Required: F[G[T]]
9+
| value f is not a member of T.
10+
| An extension method was tried, but could not be fully constructed:
11+
|
12+
| Test.f[G[T]](x)(given_Stuff) failed with
13+
|
14+
| Found: (x : T)
15+
| Required: G[T]
1116
-- [E007] Type Mismatch Error: tests/neg/i6779.scala:14:38 -------------------------------------------------------------
1217
14 | def g3[T](x: T): F[G[T]] = this.f(x)(using summon[Stuff]) // error
1318
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

tests/neg/i8032.check

Lines changed: 0 additions & 9 deletions
This file was deleted.

tests/semanticdb/expect/Enums.expect.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ object Enums/*<-_empty_::Enums.*/:
5252
extension [A/*<-_empty_::Enums.unwrap().[A]*/, B/*<-_empty_::Enums.unwrap().[B]*/](opt/*<-_empty_::Enums.unwrap().(opt)*/: Option/*->scala::Option#*/[A/*->_empty_::Enums.unwrap().[A]*/]) def unwrap/*<-_empty_::Enums.unwrap().*/(using ev/*<-_empty_::Enums.unwrap().(ev)*/: A/*->_empty_::Enums.unwrap().[A]*/ <:</*->_empty_::Enums.`<:<`#*/ Option/*->scala::Option#*/[B/*->_empty_::Enums.unwrap().[B]*/]): Option/*->scala::Option#*/[B/*->_empty_::Enums.unwrap().[B]*/] = ev/*->_empty_::Enums.unwrap().(ev)*/ match
5353
case Refl/*->_empty_::Enums.`<:<`.Refl.*//*->_empty_::Enums.`<:<`.Refl.unapply().*/() => opt/*->_empty_::Enums.unwrap().(opt)*/.flatMap/*->scala::Option#flatMap().*/(identity/*->scala::Predef.identity().*//*->local0*/[Option/*->scala::Option#*/[B/*->_empty_::Enums.unwrap().[B]*/]])
5454

55-
val some1/*<-_empty_::Enums.some1.*/ = /*->_empty_::Enums.unwrap().*/Some/*->scala::Some.*//*->scala::Some.apply().*/(Some/*->scala::Some.*//*->scala::Some.apply().*/(1))/*->_empty_::Enums.`<:<`.given_T().*/.unwrap
55+
val some1/*<-_empty_::Enums.some1.*/ = /*->_empty_::Enums.unwrap().*/Some/*->scala::Some.*//*->scala::Some.apply().*/(Some/*->scala::Some.*//*->scala::Some.apply().*/(1)).unwrap/*->_empty_::Enums.`<:<`.given_T().*/
5656

5757
enum Planet/*<-_empty_::Enums.Planet#*/(mass/*<-_empty_::Enums.Planet#mass.*/: Double/*->scala::Double#*/, radius/*<-_empty_::Enums.Planet#radius.*/: Double/*->scala::Double#*/) extends Enum/*->java::lang::Enum#*/[Planet/*->_empty_::Enums.Planet#*/]/*->java::lang::Enum#`<init>`().*/:
5858
private final val G/*<-_empty_::Enums.Planet#G.*/ = 6.67300E-11

tests/semanticdb/metac.expect

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -971,7 +971,7 @@ Occurrences:
971971
[54:18..54:18): -> scala/Some.apply().
972972
[54:19..54:23): Some -> scala/Some.
973973
[54:23..54:23): -> scala/Some.apply().
974-
[54:27..54:27): -> _empty_/Enums.`<:<`.given_T().
974+
[54:34..54:34): -> _empty_/Enums.`<:<`.given_T().
975975
[56:7..56:13): Planet <- _empty_/Enums.Planet#
976976
[56:13..56:13): <- _empty_/Enums.Planet#`<init>`().
977977
[56:14..56:18): mass <- _empty_/Enums.Planet#mass.

0 commit comments

Comments
 (0)