8000 Field access is resolved as a call to any same-named function in the program · Issue #448 · kexhq/kex · GitHub
[go: up one dir, main page]

Skip to content

Field access is resolved as a call to any same-named function in the program #448

Closed

Description

@akoskovacs

value.field is taken as the UFCS call field(value) whenever a function of that name is visible, and it wins over the record's own field. Depending on the case this is a type error, a wrong value, or (in a spec with Harmat) a silently wrong result.

Cases

1. Wrong value at run time. With using Harmat.Schema, only: [text] in scope:

record Statement do
  text : String
  values : [String] = []
end

let q = Statement { text: "SELECT 1" }
Assert.equal(q.text, "SELECT 1")
# expected SELECT 1, got Harmat.Schema.TextColumn { label: Statement { text: SELECT 1, values: [] } }

q.text ran text(q). Harmat.Query already names its field statement for this reason, citing an in-repo precedent in regex.kex.

2. Type error against a prelude function. A record with a name field, reached through a method declared in another file:

let mortgage = draft.holding
Assert.equal(mortgage.name, "Home mortgage")
# error: `name` expects argument 1 to be Weekday, but got Holding
#   name : Weekday -> String

and likewise `value` expects 2 argument(s), got 1 for a value field.

3. Inside .ket templates. With a typed parameter section: Section whose record has a code field, and an unrelated App.Models.Kind.code : Kind -> String elsewhere in the program (not imported by the template's module):

<template>:1:9: error: `code` expects argument 1 to be App.Models.Kind.Kind, but got Section

The same for fields named name, value, kind, facts, plural, singular.

Expected

When the receiver's static type is a record with that field, the field wins. A same-named function should only be considered when the type has no such field.

Workaround

Field names that no function shares (title, caption, content, anchor…), which gets harder as a program grows.

Related: #242 and #234 (closed) covered narrower versions of this.

Environment: Kex 0.4.0-rc.1 (30c7979), Tey 0.2.1, Erlang/OTP 29.0.5 (Homebrew), macOS arm64. Found while building an application on Rodolfo 0.2 and Harmat 0.1.

Activity

  1. akoskovacs commented on Oct 17, 2026

    @akoskovacs
    CollaboratorAuthor

    Fixed on current main (0fd796c) by #478 and #482. All three cases were checked on both backends, with the colliding function in another module of the program:

    1. q.text on a Statement with an imported text function in scope gives SELECT 1.
    2. mortgage.name and mortgage.value on a record reached through another module's function give the fields.
    3. In a .ket template with params: [section: Section], section.code reads the field while another module defines code : Kind -> String.
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