8000 An overloaded || is typed as Bool when its left side comes from another module's method · Issue #532 · kexhq/kex · GitHub
[go: up one dir, main page]

Skip to content

An overloaded || is typed as Bool when its left side comes from another module's method #532

Closed

Description

@akoskovacs

Since #528, a make block can overload && and ||. In Harmat that works when a condition's left side is built from Harmat.Schema, but not when it comes from a method of another module: the checker types the || as Bool.

Harmat's src/harmat/schema.kex (module Harmat.Schema do … end):

type Cond = EqCond(String, Any)
  | AnyCond([Cond])
  ...

make TextColumn do
  let ==(val: String) -> Harmat.Schema.Cond = EqCond(@label, val)
end

make Cond do
  let ||(other: Harmat.Schema.Cond) -> Harmat.Schema.Cond = AnyCond(Harmat.Schema.parts(this, other, true))
end

A spec in the Harmat package:

using Harmat.Table, as: Table

let users = Table.define :users do |t|
  t.text(:owner)
end

# `textColumn` is a method of Harmat.Table's Definition; it answers a Harmat.Schema.TextColumn.
let owner = users.textColumn(:owner)

describe("or") do
  it("joins") do
    Assert.equal(Harmat.Database.select().from(users).where(owner == "a" || owner == "b").conditions.count, 1)
  end
end

On main at 6fdaf4c:

error: `where` expects argument 2 to be Cond, but got Bool

It passes when:

  • the left side is Harmat.Schema.text("owner") == "a", or
  • the spec adds using Harmat.Schema, only: [Cond].

A smaller package with the same shape (sum type and make in one module, the column from a make method of another, where overloaded on several records) does not reproduce it, so there is something more about Harmat's layout. The Harmat change that adds || is going up soon.

Also: #528 says && and || can go in using … only: lists, but using Harmat.Schema, only: [||, &&] fails with Expected name in using option list.

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

    No labels
    No labels

    Type

    No type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    0