New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weird illegal cyclic reference while building on 2.12 #679

Open
danslapman opened this Issue Jan 17, 2017 · 7 comments

Comments

Projects
None yet
2 participants
@danslapman

danslapman commented Jan 17, 2017

I just faced really weird illegal cyclic reference error when build my project on scala 2.12.1

Code is here: https://github.com/danslapman/shapeless-play-json/blob/master/src/test/scala/shapelessplayjson/strict/RecordDeserializationTests.scala

It compiles without any trouble on 2.11.8

I may be a scala regression, but it also can be an issue in record macro expansion, so I'm submiting it here

@ghost

This comment has been minimized.

Show comment
Hide comment
@ghost

ghost Jan 19, 2017

@danslapman it appears to be scalac trying to double-lock a symbol (it compiles with -Yrecursion 1 for me).

ghost commented Jan 19, 2017

@danslapman it appears to be scalac trying to double-lock a symbol (it compiles with -Yrecursion 1 for me).

@danslapman

This comment has been minimized.

Show comment
Hide comment
@danslapman

danslapman Jan 19, 2017

@allisonhb thank You, -Yrecursion 1 worked. Could you please explain, why it happened? Is it a regression I may report to scalac?

danslapman commented Jan 19, 2017

@allisonhb thank You, -Yrecursion 1 worked. Could you please explain, why it happened? Is it a regression I may report to scalac?

@milessabin

This comment has been minimized.

Show comment
Hide comment
@milessabin

milessabin Jan 19, 2017

Owner

Yes, I would very much like to know what's going on here ... it's the first time I've seen a problem of this sort.

Owner

milessabin commented Jan 19, 2017

Yes, I would very much like to know what's going on here ... it's the first time I've seen a problem of this sort.

@milessabin

This comment has been minimized.

Show comment
Hide comment
@milessabin

milessabin Jan 19, 2017

Owner

@allisonhb BTW, I would like to attribute you properly, both for your shapeless contributions, and also for the scala/scala PR of yours that I'm going to include in the next TLS releases. No problem if you'd rather not, but a PR against CONTRIBUTORS here would be very welcome.

Owner

milessabin commented Jan 19, 2017

@allisonhb BTW, I would like to attribute you properly, both for your shapeless contributions, and also for the scala/scala PR of yours that I'm going to include in the next TLS releases. No problem if you'd rather not, but a PR against CONTRIBUTORS here would be very welcome.

@ghost

This comment has been minimized.

Show comment
Hide comment
@ghost

ghost Jan 21, 2017

Thanks, @milessabin! I'll PR it in if/when I get this fixed...

I'm still grubbing around in the dirt for the problem here, but it appears that something is causing scalac to do an implicit search while typing type Book = ..., during which it stumbles upon your implicit val, looks at the type, and chokes because it was in the middle of initializing the symbol for Book.

This compiles fine:

trait Reads[A] {
  def read(s: String): A
}
trait KDecl {
  import shapeless.record._
  type K = Record.`'key -> Int`.T
}
object Foo extends KDecl {
  implicit val rk : Reads[K] = (s: String) => ???
}

but this fails:

trait Reads[A] {
  def read(s: String): A
}
object Foo {
  import shapeless.record._
  type K = Record.`'key -> Int`.T
  implicit val k : Reads[K] = (s: String) => ???
}

My first suspicion was actually mkTypeCarrier for calling c.typecheck, but it appears that we fail even before then, which is strange. I'll let you know what else I find and if there will be a pr to here or scala/scala...

EDIT:

A good reason for it to be searching for an implicit conversion is because we're calling a non-existent method on Record... this may be a bug caused by scala looking for implicit views before invoking selectDynamic.

ghost commented Jan 21, 2017

Thanks, @milessabin! I'll PR it in if/when I get this fixed...

I'm still grubbing around in the dirt for the problem here, but it appears that something is causing scalac to do an implicit search while typing type Book = ..., during which it stumbles upon your implicit val, looks at the type, and chokes because it was in the middle of initializing the symbol for Book.

This compiles fine:

trait Reads[A] {
  def read(s: String): A
}
trait KDecl {
  import shapeless.record._
  type K = Record.`'key -> Int`.T
}
object Foo extends KDecl {
  implicit val rk : Reads[K] = (s: String) => ???
}

but this fails:

trait Reads[A] {
  def read(s: String): A
}
object Foo {
  import shapeless.record._
  type K = Record.`'key -> Int`.T
  implicit val k : Reads[K] = (s: String) => ???
}

My first suspicion was actually mkTypeCarrier for calling c.typecheck, but it appears that we fail even before then, which is strange. I'll let you know what else I find and if there will be a pr to here or scala/scala...

EDIT:

A good reason for it to be searching for an implicit conversion is because we're calling a non-existent method on Record... this may be a bug caused by scala looking for implicit views before invoking selectDynamic.

@milessabin

This comment has been minimized.

Show comment
Hide comment
@milessabin

milessabin Jan 24, 2017

Owner

Good stuff!

Owner

milessabin commented Jan 24, 2017

Good stuff!

@ghost

This comment has been minimized.

Show comment
Hide comment
@ghost

ghost Jan 24, 2017

Heh, thanks also for the withPropagateCyclicReferences...

ghost commented Jan 24, 2017

Heh, thanks also for the withPropagateCyclicReferences...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment