Skip to content

really flakey implicit resolution #5978

Closed
@drdozer

Description

@drdozer

Consider:

import scala.language.implicitConversions

opaque type Position[Buffer] = Int


trait TokenParser[Token, R]

object TextParser {
  implied TP for TokenParser[Char, Position[CharSequence]] {}

  implied FromCharToken
    given (T: TokenParser[Char, Position[CharSequence]]) for Conversion[Char, Position[CharSequence]] = ???

}


object Testcase {
  def main(args: Array[String]): Unit = {
    import TextParser._

    val tp_v: TokenParser[Char, Position[CharSequence]] = TextParser.TP // compiles
    val tp_i = infer[TokenParser[Char, Position[CharSequence]]] // does not compile
    val co_i = infer[Conversion[Char, Position[CharSequence]]] // does not compile
    val co_x : Position[CharSequence] = 'x'

    {
      implied XXX for Conversion[Char, Position[CharSequence]] = co_i
      val co_y : Position[CharSequence] = 'x' // compiles
    }

  }
}

This fails, as commented. However, if I add other seemingly unrelated statements, some or all of it may compile. I can find no rhyme or reason to it. If I make the implied declarations top-level, it works. In other situations, the statment co_x only works if the anonymous block following is present. If I comment that block out, then co_x no longer works. Again, I have no idea what I've done to the surrounding codebase to trigger this weird bug.

If I had to guess, I'd say there was 1. an issue with implied instance visibility, and 2. some issue with expressions being typed more completely in some situations than others. But honestly, I'm mystified. Some issues appear to empirically go away if I move everything to top-level declarations, but that is messy from a scoping point of view.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions