8000 A postfix `return x if cond` is not checked against the declared return type · Issue #723 · kexhq/kex · GitHub
[go: up one dir, main page]

Skip to content

A postfix return x if cond is not checked against the declared return type #723

Closed

Description

@akoskovacs

A return in the postfix-if form isn't checked against the function's declared return type. The block form is checked.

let label(n: Integer) -> Integer do
  return "negative" if n < 0
  n
end

main do
  let x = label(-1)
  IO.printLine(x + 1)
end
  • kex -C: No errors found.
  • kex --run-walker: runtime error: cannot add String and Integer at the x + 1.
  • kex (BEAM): Internal error: badarith.

The checker believes label answers an Integer, so the String comes out at the caller, far from where it was returned.

The same return written as a block is rejected, as expected:

let plain(n: Integer) -> Integer do
  if n < 0
    return "negative"
  end
  n
end
8:5: [KEXET-0124]: Error, `plain` declared to return Integer but returns String here

So KEXET-0124's check reaches a return inside an if block, but not a return that is the body of a postfix if. Expected: the postfix form reports KEXET-0124 at the return too.

Found while working on #719, on main at d74de6d.

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

    BugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0