8000 `sum` over `[Integer]` is typed `Number`, so it cannot be returned as `Integer` · Issue #752 · kexhq/kex · GitHub
[go: up one dir, main page]

Skip to content

sum over [Integer] is typed Number, so it cannot be returned as Integer #752

Open

Description

@akoskovacs

sum over a list of integers is typed Number, so a function that sums integers cannot declare -> Integer:

record Item do
  count : Integer
end

let total(items: [Item]) -> Integer = items.map { |i| i.count }.sum
sum.kex:5:68: [KEXET-0127]: Error, `total` declared to return Integer but body returns Number

The element type is not the problem: kex -C -t on [1, 2, 3].map { |x| x * 2 }.sum types the mapped list as [Integer] and only the .sum as Number.

Expected: sum over [Integer] is Integer (and over [Float] is Float), i.e. its result is the element type, or at least Integer is accepted where the declared result is Integer.

Seen on 0.4.0-rc.4 (0292db50), macOS arm64, OTP 29.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0