scala/scala3
在 GitHub 查看compiletime ops could interpret non-literal arguments under algebraic laws
Open
#9,792 创建于 2020年9月14日
help wanteditype:bug
仓库指标
- Star
- (6,247 star)
- PR 合并指标
- (平均合并 18天 14小时) (30 天内合并 133 个 PR)
描述
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