8000 Builder-chain collapse hides type errors in the chain's arguments (Harmat: credit >= "lots" checks clean) · Issue #761 · kexhq/kex · GitHub
[go: up one dir, main page]

Skip to content

Builder-chain collapse hides type errors in the chain's arguments (Harmat: credit >= "lots" checks clean) #761

Open

Description

@akoskovacs

When the compiler evaluates a builder chain at compile time ("chain collapse"), a type error in an argument inside that chain is no longer reported. The program checks clean, although the same expression outside the chain is rejected.

Reproduced with Harmat (kexhq/harmat, src/ passed with --source-root). IntColumn declares >=(val: Integer) -> Cond only.

using Harmat.Table, as: Table
using Harmat.Database, as: Database

compiled do
  let users = Table.define :users do |t|
    t.text(:email, primaryKey: true)
    t.bigint(:credit, default: 0)
  end
  let credit = users.wholeColumn(:credit)
end

record User do
  email  : String
  credit : Integer
end

foul richest(limit: Integer) -> [User] or! String do
  Database.select([:email, :credit])
    .from(users)
    .where(credit >= "lots")          # String where an Integer is required
    .orderBy(descending: [:credit])
    .limit(limit)
    .all(as: User)
end

main do
  IO.printLine("ok")
end
$ kex -C --source-root ../harmat/src q.kex
No errors found.
$ kex --collapse-report -C --source-root ../harmat/src q.kex
collapse: 1 of 2 evaluated at compile time
  q.kex:21:13 collapsed
  q.kex:22:11 kept — the value of `limit` is not known at compile time, ...
No errors found.

The same comparison outside a chain is rejected, with or without compiled do:

<
6EB3
code class="notranslate">let c = credit >= "lots"
[KEXET-0491]: Error, `>=` expects argument 2 to be Integer, but got String
>= : Harmat.Schema.IntColumn -> Integer -> Harmat.Schema.Cond

kex -C -t on the program above reports every expression of the collapsed part of the chain at one position (21:13, the .orderBy), and none at credit >= "lots" on line 20.

A related symptom with the same cause: .where(credit == "five") is reported, but at the .orderBy on the next line, and as `Harmat.Database.Select.conditions` expects [Harmat.Schema.Cond], but got [Bool]. That message comes from inside Harmat, not from the line the user wrote.

Expected: the checker reports argument errors in a chain at their own positions, whether or not the chain is later collapsed. Harmat's README relies on this ("credit == "five" does not build").

Kex 0.4.0-rc.4 (294556f), 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