You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
An overloaded || is typed as Bool when its left side comes from another module's method #532
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
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.
Activity