-
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.
Merge pull request #4738 from dotty-staging/fix-#876
Fix #876: Allow implicit conversions from singleton types
- Loading branch information
Showing
7 changed files
with
65 additions
and
18 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
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,8 @@ | ||
object Test { | ||
val a: Int = 1 | ||
implicit def foo(x: a.type): String = "hi" | ||
val b: Int = a | ||
|
||
val x: String = a // ok | ||
val y: String = b // error: found Int, required String | ||
} |
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,22 @@ | ||
object Test extends App { | ||
object O | ||
implicit def foo(x: O.type): String = "hello" | ||
val s: String = O | ||
implicit def bar(x: s.type): Int = s.length | ||
//implicit def bar2(x: String): Int = s.length | ||
val l: Int = s | ||
assert(s == "hello") | ||
assert(l == 5) | ||
} | ||
|
||
object Test3781 { | ||
class Foo[T](val value : T) | ||
object Foo { | ||
implicit def fromXInt[T <: Int with Singleton](i : T): Foo[T] = new Foo[T](i) | ||
} | ||
class FooUser[T] { | ||
def op[T2](that : Foo[T2]) : FooUser[T2] = new FooUser[T2] | ||
} | ||
val f = new FooUser[1] | ||
val f2 = f op 2 | ||
} |