8000 Record name called like a function: `Point(x: 1, y: 2)` passes the checker, fails on both backends · Issue #747 · kexhq/kex · GitHub
[go: up one dir, main page]

Skip to content

Record name called like a function: Point(x: 1, y: 2) passes the checker, fails on both backends #747

Open

Description

@akoskovacs

Calling a record's name like a function, Point(x: 1, y: 2), passes kex -C but fails on both backends. The checker doesn't look at the named arguments at all: Point(z: "no") also checks clean.

record Point do
  x : Integer
  y : Integer
end

main do
  let p = Point(x: 1, y: 2)
  IO.printLine(p.x)
end
Form kex -C BEAM (kex) walker (kex -R)
Point(x: 1, y: 2) No errors found [KEXEB-0030]: Error, IR lower: named args to unknown function Point Internal error: …:7:11: runtime error: 'Point' is not callable
Point(1, 2) No errors found runs, prints 1 Internal error: … 'Point' is not callable
Point(x: 1) No errors found — —
Point(z: "no") No errors found KEXEB-0030 'Point' is not callable
Point { x: 1, y: 2 } No errors found prints 1 prints 1

Problems

  1. The checker accepts a call on a record name with any arguments: unknown fields, missing fields and wrong types all pass.
  2. BEAM and the walker disagree on positional Point(1, 2): BEAM builds the record, the walker rejects it at runtime.
  3. The walker's failure is reported as an Internal error ("a bug in the Kex compiler") rather than a diagnostic.

Expected: decide whether Point(...) is a constructor call. If it isn't, which the guide suggests (make.md only constructs with Point { … }), the checker should reject it with a diagnostic that points at Point { x: 1, y: 2 }, and lowering should never be reached. If it is, the checker should check the arguments against the fields, and the walker should accept the forms BEAM does.

Seen on 0.4.0-rc.4 (294556f2), macOS arm64.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0