scala - "Type arguments do not conform to class' type parameter bounds" under specific conditions -


given these classes in scala 2.11.8:

class a[t] {   class p[tt >: t]    def p[tt >: t]: p[tt] = new p[tt] } class b[t](val a: a[t]) {   def p[tt >: t]: a.p[tt] = a.p[tt] } class x class y extends x 

the following line produces compile error type arguments [object] not conform class p's type parameter bounds [tt >: t] (even though x >: y):

val x = new b[y](new a[y]).p[x] 

interestingly, error not appear in following code:

new b[y](new a[y]).p[x]  val y = new b[y](new a[y]) val z = y.p[x] 

what difference not seeing?

i had hunch compiler not assign type x, seems strange given in following code, q happily assigned a[y]#p[x]:

val q = new a[y].p[x] 

as far can tell, x should assigned a[y]#p[x].

the repl gave me think clue, i'm not sure how:

scala> :t new b[y](new a[y]).p[any] _6.a.p[any] forsome { val _6: b[y] } 

_6.a.p[any] forsome { val _6: b[y] } along lines of b[y]#a.p[any] (pseudocode), seems logically equivalent a[y]#p[any]. seems fact compiler can't turn a[y]#p[any] may bug?

my next hunch compiler couldn't turn new b[y](new a[y]).p[any] a[y]#p[any] because argument b's constructor polymorphic. define class:

class c[t] extends a[t] 

and new b[y](new c[y]).p[any] c[y]#p[any]. a[y]#p[any] >: c[y]#p[any], should safe compiler assign new b[y](...).p[any] type a[y]#p[any]. i'm being convinced compiler bug.

another interesting detail note error disappears if return type of b.p changed a[t]#p[tt].


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -