Skip to content
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

Divergent Implicit Type Error for SeqProperty #271

Closed
KGoodale13 opened this issue Apr 8, 2019 · 1 comment · Fixed by #276
Closed

Divergent Implicit Type Error for SeqProperty #271

KGoodale13 opened this issue Apr 8, 2019 · 1 comment · Fixed by #276
Assignees
Labels
Milestone

Comments

@KGoodale13
Copy link
Contributor

The following code puts the compiler into an infinite loop possibly because of a DivergentImplicitTypeError (Not completely sure it is infinite but I gave it a solid 20 minutes before I killed it):

private case class Chunk[T](
    var requested: Boolean = false,
    data: SeqProperty[T] = SeqProperty.blank
)

If I change SeqProperty.blank to SeqProperty.blank[T] it will throw an error saying it cannot find a implicit ProperyCreator[T] as it should.

@ddworak ddworak self-assigned this Apr 8, 2019
@ddworak ddworak added the bug label Apr 8, 2019
@ddworak ddworak added this to the 0.8.0 milestone Apr 8, 2019
@ddworak
Copy link
Member

ddworak commented Apr 16, 2019

Thanks for the report!

The underlying issue is that you actually cannot do it like this in Scala, e.g. https://scalafiddle.io/sf/OVcJbld/0

case class Property[T]()
object Property {
  def create[T]: Property[T] = Property()
}

case class Dummy[T](
  p: Property[T] = Property.create  
)

val x = Dummy[Int]()

won't compile due to:

error: type mismatch;
 found   : ScalaFiddle.this.Property[scala.this.Nothing]
 required: ScalaFiddle.this.Property[scala.this.Int]
Note: scala.this.Nothing <: scala.this.Int, but class Property is invariant in type T.
You may wish to define T as +T instead. (SLS 4.5)
Error occurred in an application involving default arguments.
  val x = Dummy[Int]()
               ^

This unexpected behaviour is actually a part of the spec:
The default argument expression e is type-checked with an expected type T' obtained by replacing all occurrences of the function's type parameters in T by the undefined type
and in case of these implicits leads to huge mess in implicit resolution. More details: scala/scala-dev#366 (comment)

Anyway, I've managed to reduce the number of implicit defs and macro usage to the point where detecting the issue is acceptably fast and covered by our test suite. #276

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants