-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refine AsSeenFrom approximation scheme (#15957)
The previous scheme did not set the approximated flag in some cases, which led to the appearance of unhelpful Nothing types in error messages. We now always mark the AsSeenFrom map as approximated when encountering an illegal prefix at variance <= 0. But we reset it again when a range in a prefix is dropped because we can follow a type alias or use a singleton type info. Furthermore, we use an `Int`, `approxCount` instead of `approximated` to keep track of multiple approximation points. Fixes #15939 in the sense that the error message now makes more sense. We still cannot find the implicit conversion; that would require a more global measure to fix the problem (such as going to ANF) or existential types.
- Loading branch information
Showing
4 changed files
with
95 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
-- [E007] Type Mismatch Error: tests/neg/i15939.scala:19:16 ------------------------------------------------------------ | ||
19 | mkFoo.andThen(mkBarString) // error | ||
| ^^^^^^^^^^^ | ||
| Found: String | ||
| Required: ?1.Bar | ||
| | ||
| where: ?1 is an unknown value of type Test.Foo | ||
| | ||
| longer explanation available when compiling with `-explain` | ||
-- [E007] Type Mismatch Error: tests/neg/i15939.scala:20:2 ------------------------------------------------------------- | ||
20 | mkBarString andThen_: mkFoo // error | ||
| ^^^^^^^^^^^ | ||
| Found: String | ||
| Required: ?2.Bar | ||
| | ||
| where: ?2 is an unknown value of type Test.Foo | ||
| | ||
| longer explanation available when compiling with `-explain` | ||
-- [E007] Type Mismatch Error: tests/neg/i15939.scala:21:18 ------------------------------------------------------------ | ||
21 | mkFoo.andThen_:(mkBarString) // error | ||
| ^^^^^^^^^^^ | ||
| Found: String | ||
| Required: ?3.Bar | ||
| | ||
| where: ?3 is an unknown value of type Test.Foo | ||
| | ||
| longer explanation available when compiling with `-explain` | ||
-- [E007] Type Mismatch Error: tests/neg/i15939.scala:22:2 ------------------------------------------------------------- | ||
22 | mkBarString andThenByName_: mkFoo // error | ||
| ^^^^^^^^^^^ | ||
| Found: String | ||
| Required: ?4.Bar | ||
| | ||
| where: ?4 is an unknown value of type Test.Foo | ||
| | ||
| longer explanation available when compiling with `-explain` | ||
-- [E007] Type Mismatch Error: tests/neg/i15939.scala:23:24 ------------------------------------------------------------ | ||
23 | mkFoo.andThenByName_:(mkBarString) // error | ||
| ^^^^^^^^^^^ | ||
| Found: String | ||
| Required: ?5.Bar | ||
| | ||
| where: ?5 is an unknown value of type Test.Foo | ||
| | ||
| longer explanation available when compiling with `-explain` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import scala.language.implicitConversions | ||
|
||
object Test { | ||
class Foo { | ||
class Bar { | ||
override def toString() = "bar" | ||
} | ||
object Bar { | ||
implicit def fromString(a: String): Bar = { println("convert bar") ; new Bar } | ||
} | ||
|
||
def andThen(b: Bar): Unit = { println("pre") ; println(s"use $b") ; println("post") } | ||
def andThen_:(b: Bar) = { println("pre") ; println(s"use $b") ; println("post") } | ||
def andThenByName_:(b: => Bar) = { println("pre") ; println(s"use $b") ; println(s"use $b") ; println("post") } | ||
} | ||
|
||
def mkFoo: Foo = ??? | ||
def mkBarString: String = ??? | ||
mkFoo.andThen(mkBarString) // error | ||
mkBarString andThen_: mkFoo // error | ||
mkFoo.andThen_:(mkBarString) // error | ||
mkBarString andThenByName_: mkFoo // error | ||
mkFoo.andThenByName_:(mkBarString) // error | ||
} |