Created
May 1, 2010 12:13
-
-
Save retronym/386283 to your computer and use it in GitHub Desktop.
bug with implicits and type inference
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
// Making Zero covariant in Z allows compilation | |
trait Zero[/*+*/Z] { | |
val zero: Z | |
} | |
object Zero { | |
implicit def IntZero: Zero[Int] = error("stub") | |
// removing UnitZero allows compilation | |
implicit def UnitZero: Zero[Unit] = error("stub") | |
} | |
object Scalaz { | |
def mzero[ZZ](implicit z: Zero[ZZ]): ZZ = z.zero | |
} | |
object test { | |
import Scalaz._ | |
// Passing type argument Int explicitly allows compilation: mzero[Int] | |
mzero: Int | |
} | |
// (fragment of zero.scala):18: error: ambiguous implicit values: | |
// both method UnitZero in object Zero of type => this.Zero[Unit] | |
// and method IntZero in object Zero of type => this.Zero[Int] | |
// match expected type this.Zero[ZZ] | |
// mzero: Int | |
// ^ | |
// one error found |
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
typing (mzero: Int), pt = ?, undetparams = List(), implicits-enabled = true, silent = true | |
typing Int, pt = ?, undetparams = List(), implicits-enabled = true, silent = true | |
typed scala.Int:Int, undetparams = List(), pt = ? | |
adapted scala.Int:Int to ?, List() | |
typing mzero, pt = Int, undetparams = List(), implicits-enabled = true, silent = true | |
typed Scalaz.mzero:[ZZ](implicit z: Zero[ZZ])ZZ, undetparams = List(), pt = Int | |
typing implicit with undetermined type params: List(type ZZ) | |
Scalaz.mzero[ZZ] | |
typed impl?? UnitZero:=> Zero[Unit] ==> Zero.UnitZero with pt = Zero[ZZ], wildpt = Zero[?] | |
typing Zero, pt = ?, undetparams = List(), implicits-enabled = false, silent = false | |
typed Zero:Zero.type with underlying object Zero, undetparams = List(), pt = ? | |
adapted Zero:object Zero to ?, List() | |
typed implicit Zero.UnitZero:=> Zero[Unit], pt = Zero[?] | |
adapted implicit method UnitZero:Zero[Unit] to Zero[?] | |
tvars = List(?ZZ)/List([ _>:(Unit) | _<:(Unit) ] _= <notype>) | |
RESULT = SearchResult(Zero.UnitZero, TreeTypeSubstituter(List(type ZZ),List(Unit))) | |
typed impl?? IntZero:=> Zero[Int] ==> Zero.IntZero with pt = Zero[ZZ], wildpt = Zero[?] | |
typing Zero, pt = ?, undetparams = List(), implicits-enabled = false, silent = false | |
typed Zero:Zero.type with underlying object Zero, undetparams = List(), pt = ? | |
adapted Zero:object Zero to ?, List() | |
typed implicit Zero.IntZero:=> Zero[Int], pt = Zero[?] | |
adapted implicit method IntZero:Zero[Int] to Zero[?] | |
tvars = List(?ZZ)/List([ _>:(Int) | _<:(Int) ] _= <notype>) | |
RESULT = SearchResult(Zero.IntZero, TreeTypeSubstituter(List(type ZZ),List(Int))) | |
typing mzero, pt = ?, undetparams = List(type ZZ), implicits-enabled = true, silent = true | |
typed Scalaz.mzero:[ZZ](implicit z: Zero[ZZ])ZZ, undetparams = List(type ZZ), pt = ? | |
typing implicit with undetermined type params: List(type ZZ, type ZZ) | |
Scalaz.mzero[ZZ] | |
typed impl?? UnitZero:=> Zero[Unit] ==> Zero.UnitZero with pt = Zero[ZZ], wildpt = Zero[?] | |
typing Zero, pt = ?, undetparams = List(), implicits-enabled = false, silent = false | |
typed Zero:Zero.type with underlying object Zero, undetparams = List(), pt = ? | |
adapted Zero:object Zero to ?, List() | |
typed implicit Zero.UnitZero:=> Zero[Unit], pt = Zero[?] | |
adapted implicit method UnitZero:Zero[Unit] to Zero[?] | |
tvars = List(?ZZ, ?ZZ)/List([ _>:() | _<:() ] _= <notype>, [ _>:(Unit) | _<:(Unit) ] _= <notype>) | |
RESULT = SearchResult(Zero.UnitZero, TreeTypeSubstituter(List(type ZZ),List(Unit))) | |
typed impl?? IntZero:=> Zero[Int] ==> Zero.IntZero with pt = Zero[ZZ], wildpt = Zero[?] | |
typing Zero, pt = ?, undetparams = List(), implicits-enabled = false, silent = false | |
typed Zero:Zero.type with underlying object Zero, undetparams = List(), pt = ? | |
adapted Zero:object Zero to ?, List() | |
typed implicit Zero.IntZero:=> Zero[Int], pt = Zero[?] | |
adapted implicit method IntZero:Zero[Int] to Zero[?] | |
tvars = List(?ZZ, ?ZZ)/List([ _>:() | _<:() ] _= <notype>, [ _>:(Int) | _<:(Int) ] _= <notype>) | |
RESULT = SearchResult(Zero.IntZero, TreeTypeSubstituter(List(type ZZ),List(Int))) | |
caught scala.tools.nsc.symtab.Types$TypeError: ambiguous implicit values: | |
both method UnitZero in object Zero of type => Zero[Unit] | |
and method IntZero in object Zero of type => Zero[Int] | |
match expected type Zero[ZZ] in typed: mzero | |
zero.scala:18: error: ambiguous implicit values: | |
both method UnitZero in object Zero of type => Zero[Unit] | |
and method IntZero in object Zero of type => Zero[Int] | |
match expected type Zero[ZZ] | |
mzero: Int | |
^ | |
adapted Scalaz.mzero:[ZZ](implicit z: Zero[ZZ])ZZ to Int, List() | |
typed (<error: <none>>: Int):Int, undetparams = List(), pt = ? |
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
typing (mzero: Int), pt = ?, undetparams = List(), implicits-enabled = true, silent = true | |
typing Int, pt = ?, undetparams = List(), implicits-enabled = true, silent = true | |
typed scala.Int:Int, undetparams = List(), pt = ? | |
adapted scala.Int:Int to ?, List() | |
typing mzero, pt = Int, undetparams = List(), implicits-enabled = true, silent = true | |
typed Scalaz.mzero:[ZZ](implicit z: Zero[ZZ])ZZ, undetparams = List(), pt = Int | |
typed impl?? IntZero:=> Zero[Int] ==> Zero.IntZero with pt = Zero[Int], wildpt = Zero[Int] | |
typing Zero, pt = ?, undetparams = List(), implicits-enabled = false, silent = false | |
typed Zero:Zero.type with underlying object Zero, undetparams = List(), pt = ? | |
adapted Zero:object Zero to ?, List() | |
typed implicit Zero.IntZero:=> Zero[Int], pt = Zero[Int] | |
adapted implicit method IntZero:Zero[Int] to Zero[Int] | |
tvars = List()/List() | |
RESULT = SearchResult(Zero.IntZero, TreeTypeSubstituter(List(),List())) | |
typing Scalaz.mzero[Int](Zero.IntZero), pt = Int, undetparams = List(), implicits-enabled = true, silent | |
= false | |
typing Scalaz.mzero[Int], pt = ?, undetparams = List(), implicits-enabled = true, silent = false | |
typed Scalaz.mzero[Int]:(implicit z: Zero[Int])Int, undetparams = List(), pt = ? | |
adapted Scalaz.mzero[Int]:(implicit z: Zero[Int])Int to ?, List() | |
typing Zero.IntZero, pt = Zero[Int], undetparams = List(), implicits-enabled = true, silent = false | |
typed Zero.IntZero:Zero[Int], undetparams = List(), pt = Zero[Int] | |
adapted Zero.IntZero:Zero[Int] to Zero[Int], List() | |
typed Scalaz.mzero[Int](Zero.IntZero):Int, undetparams = List(), pt = Int | |
adapted Scalaz.mzero[Int](Zero.IntZero):Int to Int, List() | |
adapted Scalaz.mzero:[ZZ](implicit z: Zero[ZZ])ZZ to Int, List() | |
typed (Scalaz.mzero[Int](Zero.IntZero): Int):Int, undetparams = List(), pt = ? | |
adapted (Scalaz.mzero[Int](Zero.IntZero): Int):Int to ?, List() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment