Skip to content

Regression in asflierl/sglicko2 - type inference #19009

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

Closed
WojciechMazur opened this issue Nov 20, 2023 · 2 comments · Fixed by #19189
Closed

Regression in asflierl/sglicko2 - type inference #19009

WojciechMazur opened this issue Nov 20, 2023 · 2 comments · Fixed by #19189
Assignees
Labels
area:infer itype:bug regression This worked in a previous version but doesn't anymore

Comments

@WojciechMazur
Copy link
Contributor

Reproducer of failure found in Open Community Build for project asflierl/sglicko2 - build logs

Compiler version

Since 3.4.0-RC1-bin-20231113-0dfe593-NIGHTLY

Bisect points to a196167
Related issue #19001 - bisect points to the same commit, but I don't think we give any guarantees about type inference, though I've decided to create seperate issue

Minimized code

trait Player[+P]()
trait RatingPeriod[P]:
  def games: Map[P, Vector[ScoreVsPlayer[P]]]

trait ScoreVsPlayer[+P]

def updated[P](playerID: P, matchResults: IndexedSeq[ScoreVsPlayer[P]], lookup: P => Option[Player[P]]): Player[P] = ???

trait Leaderboard[P]:
  def  playersByIdInNoParticularOrder: Map[P, Player[P]]

  def after[P2 >: P](ratingPeriod: RatingPeriod[? <: P]): Leaderboard[P2] =
    val competingPlayers = ratingPeriod.games.iterator.map { (id, matchResults) => 
      updated(id, matchResults, playersByIdInNoParticularOrder.get) // error
      // workaround: 
      updated[P](id, matchResults, playersByIdInNoParticularOrder.get) 
    }
    ???

Output

-- [E007] Type Mismatch Error: /Users/wmazur/projects/sandbox/main.scala:14:32 -
14 |      updated(id, matchResults, playersByIdInNoParticularOrder.get) // error
   |                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |           Found:    Option[Player[P]]
   |           Required: Option[Player[ratingPeriod.P²]]
   |
   |           where:    P  is a type in trait Leaderboard with bounds <: P2
   |                     P² is a type in trait RatingPeriod
   |
   | longer explanation available when compiling with `-explain`
1 error found

Expectation

Should compile

@WojciechMazur WojciechMazur added itype:bug regression This worked in a previous version but doesn't anymore area: type inference labels Nov 20, 2023
@WojciechMazur
Copy link
Contributor Author

Another reproducer based on joernio/joern build logs. Again it only related to type inference

object NodeOrdering:
  def postOrderNumbering[NodeType](
    cfgEntry: NodeType,
    expand: NodeType => Iterator[NodeType]
  ): Map[NodeType, Int]  = ???

trait CfgNode
trait Method extends CfgNode

def postOrder = {
  def method: Method = ???
  def expand(x: CfgNode): Iterator[CfgNode] = ???
  NodeOrdering.postOrderNumbering(method, expand)
}

error:

-- [E007] Type Mismatch Error: /Users/wmazur/projects/dotty/bisect/main.scala:13:42 
13 |  NodeOrdering.postOrderNumbering(method, expand)
   |                                          ^^^^^^
   |                                          Found:    Iterator[CfgNode]
   |                                          Required: Iterator[Method]
   |

@WojciechMazur
Copy link
Contributor Author

Another one based on earogov/ordset - build logs

trait Bound[+E]

trait SegmentT[E, +S]
object SegmentT:
  trait WithPrev[E, +S] extends SegmentT[E, S]

trait SegmentSeqT[E, +S]:
  def getSegmentForBound(bound: Bound[E]): SegmentT[E, S] with S

abstract class AbstractSegmentSeq[E, +S] extends SegmentSeqT[E, S]

trait MappedSegmentBase[E, S]

type MappedSegment[E, S] = AbstractMappedSegmentSeq.MappedSegment[E, S]

object AbstractMappedSegmentSeq:
  type MappedSegment[E, S] = SegmentT[E, MappedSegmentBase[E, S]] with MappedSegmentBase[E, S]

abstract class AbstractMappedSegmentSeq[E, S]
    extends AbstractSegmentSeq[E, MappedSegmentBase[E, S]]:
  def originalSeq: SegmentSeqT[E, S]

  final override def getSegmentForBound(bound: Bound[E]): MappedSegment[E, S] =
    searchFrontMapper(frontMapperGeneral, originalSeq.getSegmentForBound(bound))

  protected final def frontMapperGeneral(original: SegmentT[E, S]): MappedSegment[E, S] = ???

  protected def searchFrontMapper[Seg >: SegmentT.WithPrev[E, S] <: SegmentT[E, S], R](
      mapper: Seg => R,
      original: Seg
  ): R = ???

error:

-- [E007] Type Mismatch Error: /Users/wmazur/projects/sandbox/main.scala:26:72 -
26 |    searchFrontMapper(frontMapperGeneral, originalSeq.getSegmentForBound(bound))
   |                                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |                                       Found:    SegmentT[E, S] & S
   |                                       Required: SegmentT.WithPrev[E, S]
   |

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:infer itype:bug regression This worked in a previous version but doesn't anymore
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants