scala/scala3

compiletime ops could interpret non-literal arguments under algebraic laws

Open

#9792 aperta il 14 set 2020

Vedi su GitHub
 (5 commenti) (0 reazioni) (1 assegnatario)Scala (1159 fork)batch import
help wanteditype:bug

Metriche repository

Star
 (6247 star)
Metriche merge PR
 (Merge medio 18g 14h) (133 PR mergiate in 30 g)

Descrizione

i did switch matching on 'that' instead of 'this' per @smarter 's suggestion but to no avail. operations that keeps the same list length like map and zip were ok but concat is giving me problems.

Minimized code

enum NList[N <: Int, +A]:
  def concat[M <: Int](that: NList[M, A]): NList[N + M, A] = this match
    case NNil => that
    case NCons(h, t) => NCons(h, t.concat(that))
  case NNil extends NList[0, Nothing]
  case NCons(head: A, tail: NList[N, A]) extends NList[N + 1, A]

Compiler Output

[error] -- [E007] Type Mismatch Error: 
[error] 10 |      case NNil => that
[error]    |                   ^^^^
[error]    |               Found:    (that : tlp.NLists.NList[M, A])
[error]    |               Required: tlp.NLists.NList[N + M, A]
[error]    |
[error]    |               where:    M is a type in method concat with bounds <: Int
[error] -- [E007] Type Mismatch Error:
[error] 11 |      case NCons(h, t) => NCons(h, t.concat(that))
[error]    |                                            ^^^^
[error]    |              Found:    (that : tlp.NLists.NList[M, A])
[error]    |              Required: tlp.NLists.NList[M², A$1]
[error]    |
[error]    |              where:    M  is a type in method concat with bounds <: Int
[error]    |                        M² is a type variable with constraint <: Int

Expectation

Compiles successfully

Guida contributor