Skip to content

Regression in asflierl/sglicko2 - type inference #19009

Closed
@WojciechMazur

Description

@WojciechMazur

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions