Skip to content

Commit

Permalink
Take out ambiguous negation
Browse files Browse the repository at this point in the history
  • Loading branch information
dwijnand committed Jul 27, 2023
1 parent 408d35b commit b010fad
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 40 deletions.
4 changes: 1 addition & 3 deletions compiler/src/dotty/tools/dotc/core/OrderingConstraint.scala
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,7 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
if newSet.isEmpty then deps.remove(referenced)
else deps.updated(referenced, newSet)

def traverse(t: Type) = try
t match
def traverse(t: Type) = t match
case param: TypeParamRef =>
if hasBounds(param) then
if variance >= 0 then coDeps = update(coDeps, param)
Expand All @@ -357,7 +356,6 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
seen += tp
traverse(tp.ref)
case _ => traverseChildren(t)
catch case ex: Throwable => handleRecursive("adjust", t.show, ex)
end Adjuster

/** Adjust dependencies to account for the delta of previous entry `prevEntry`
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Applications.scala
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,7 @@ trait Applications extends Compatibility {
var typedArgs = typedArgBuf.toList
def app0 = cpy.Apply(app)(normalizedFun, typedArgs) // needs to be a `def` because typedArgs can change later
val app1 =
if (!success || typedArgs.exists(_.tpe.isError)) app0.withType(UnspecifiedErrorType)
if (!success) app0.withType(UnspecifiedErrorType)
else {
if !sameSeq(args, orderedArgs)
&& !isJavaAnnotConstr(methRef.symbol)
Expand Down
17 changes: 3 additions & 14 deletions compiler/src/dotty/tools/dotc/typer/Implicits.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1328,9 +1328,7 @@ trait Implicits:
* worse than the successful candidate.
* If a trial failed:
* - if the query term is a `Not[T]` treat it as a success,
* - otherwise, if the failure is an ambiguity, try to heal it (see `healAmbiguous`)
* and return an ambiguous error otherwise. However, under Scala2 mode this is
* treated as a simple failure, with a warning that semantics will change.
* - otherwise, if the failure is an ambiguity, treat it as a simple failure.
* - otherwise add the failure to `rfailures` and continue testing the other candidates.
*/
def rank(pending: List[Candidate], found: SearchResult, rfailures: List[SearchFailure]): SearchResult =
Expand All @@ -1348,17 +1346,8 @@ trait Implicits:
case fail: SearchFailure =>
if fail eq ImplicitSearchTooLargeFailure then
fail
else if (fail.isAmbiguous)
if migrateTo3 then
val result = rank(remaining, found, NoMatchingImplicitsFailure :: rfailures)
if (result.isSuccess)
warnAmbiguousNegation(fail.reason.asInstanceOf[AmbiguousImplicits])
result
else
// The ambiguity happened in a nested search: to recover we
// need a candidate better than `cand`
healAmbiguous(fail, newCand =>
compareAlternatives(newCand, cand) > 0)
else if fail.isAmbiguous then
rank(remaining, found, NoMatchingImplicitsFailure :: rfailures)
else rank(remaining, found, fail :: rfailures)
case best: SearchSuccess =>
if (ctx.mode.is(Mode.ImplicitExploration) || isCoherent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -929,12 +929,12 @@ class SignatureHelpTest {
| def boo(x: Int, y: Int): Int = ???
| boo(${m1}, fo${m2}o1(fo${m3}o2(fo${m4}o3(fo${m5}o4(fo${m6}o5(${m7}))))))"""
.signatureHelp(m1, List(booSignature), None, 0)
.signatureHelp(m2, List(booSignature), None, 0)
.signatureHelp(m3, List(booSignature), None, 0)
.signatureHelp(m4, List(booSignature), None, 0)
.signatureHelp(m5, List(booSignature), None, 0)
.signatureHelp(m6, List(booSignature), None, 0)
.signatureHelp(m7, List(booSignature), None, 0)
.signatureHelp(m2, List(booSignature), None, 1)
.signatureHelp(m3, List(signatures(0)), None, 0)
.signatureHelp(m4, List(signatures(1)), None, 0)
.signatureHelp(m5, List(signatures(2)), None, 0)
.signatureHelp(m6, List(signatures(3)), None, 0)
.signatureHelp(m7, List(signatures(4)), None, 0)
}

@Test def multipleNestedApplySignatures: Unit = {
Expand All @@ -956,12 +956,12 @@ class SignatureHelpTest {
.signatureHelp(m1, List(simpleSignature), None, 0)
.signatureHelp(m2, List(complicatedSignature), None, 0)
.signatureHelp(m3, List(simpleSignature), None, 0)
.signatureHelp(m4, List(complicatedSignature), None, 0)
.signatureHelp(m5, List(complicatedSignature), None, 0)
.signatureHelp(m6, List(complicatedSignature), None, 0)
.signatureHelp(m7, List(complicatedSignature), None, 0)
.signatureHelp(m8, List(complicatedSignature), None, 0)
.signatureHelp(m9, List(complicatedSignature), None, 0)
.signatureHelp(m4, List(complicatedSignature), None, 1)
.signatureHelp(m5, List(complicatedSignature), None, 1)
.signatureHelp(m6, List(complicatedSignature), None, 2)
.signatureHelp(m7, List(simpleSignature), None, 0)
.signatureHelp(m8, List(complicatedSignature), None, 2)
.signatureHelp(m9, List(complicatedSignature), None, 1)
}

@Test def noHelpSignatureWithPositionedOnName: Unit = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class HoverTypeSuite extends BaseHoverSuite:
| "".<<doub@@le(1)>>
|end Foo
|""".stripMargin,
""
"extension [T](using A)(s: T) def double(using B)[G](using C)(times: G): String".hover
)

@Test def `extension-methods-complex-binary` =
Expand Down
2 changes: 1 addition & 1 deletion tests/neg-macros/i6762.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ import scala.quoted.*

type G[X]
case class Foo[T](x: T)
def f(word: String)(using Quotes): Expr[Foo[G[String]]] = '{Foo(${Expr(word)})} // error
def f(word: String)(using Quotes): Expr[Foo[G[String]]] = '{Foo(${Expr(word)})} // error // error
8 changes: 4 additions & 4 deletions tests/neg/enum-values.check
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
|
| failed with:
|
| Found: example.ListLike.type
| Required: Nothing
| Found: Array[example.Tag[?]]
| Required: Array[example.ListLike[?]]
-- [E008] Not Found Error: tests/neg/enum-values.scala:34:52 -----------------------------------------------------------
34 | val typeCtorsK: Array[TypeCtorsK[?]] = TypeCtorsK.values // error
| ^^^^^^^^^^^^^^^^^
Expand All @@ -38,8 +38,8 @@
|
| failed with:
|
| Found: example.TypeCtorsK.type
| Required: Nothing
| Found: Array[example.Tag[?]]
| Required: Array[example.TypeCtorsK[?[_$1]]]
-- [E008] Not Found Error: tests/neg/enum-values.scala:36:6 ------------------------------------------------------------
36 | Tag.valueOf("Int") // error
| ^^^^^^^^^^^
Expand Down
2 changes: 1 addition & 1 deletion tests/neg/enumsAccess.scala
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ object test5 {
enum E5[T](x: T) {
case C3() extends E5[INT](defaultX)// error: illegal reference // error: illegal reference
case C4 extends E5[INT](defaultX) // error: illegal reference // error: illegal reference
case C5 extends E5[E5[_]](E5.this) // error: cannot be instantiated // error: conflicting base types // error: type mismatch
case C5 extends E5[E5[_]](E5.this) // error: type mismatch
}

object E5 {
Expand Down
2 changes: 1 addition & 1 deletion tests/neg/i6779.check
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
| value f is not a member of T.
| An extension method was tried, but could not be fully constructed:
|
| Test.f[G[T]](x)
| Test.f[G[T]](x)(given_Stuff)
|
| failed with:
|
Expand Down
2 changes: 1 addition & 1 deletion tests/neg/recursive-lower-constraint.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ class Bar extends Foo[Bar]

class A {
def foo[T <: Foo[T], U >: Foo[T] <: T](x: T): T = x
foo(new Bar) // error // error
foo(new Bar) // error
}
6 changes: 6 additions & 0 deletions tests/neg/syntax-error-recovery.check
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@
| Not found: bam
|
| longer explanation available when compiling with `-explain`
-- [E006] Not Found Error: tests/neg/syntax-error-recovery.scala:61:10 -------------------------------------------------
61 | println(bam) // error
| ^^^
| Not found: bam
|
| longer explanation available when compiling with `-explain`
-- [E129] Potential Issue Warning: tests/neg/syntax-error-recovery.scala:7:2 -------------------------------------------
6 | 2
7 | }
Expand Down
2 changes: 1 addition & 1 deletion tests/neg/syntax-error-recovery.scala
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,5 @@ object Test2:
def foo5(x: Int) =
foo2(foo2(,) // error // error

println(bam)
println(bam) // error
// error

0 comments on commit b010fad

Please sign in to comment.