vtereshkov / umka-lang

Umka: a statically typed embeddable scripting language
BSD 2-Clause "Simplified" License
1k stars 53 forks source link

Allow implicit type casts for expression list items #402

Open skejeton opened 1 month ago

skejeton commented 1 month ago
import (
  "th.um"
  f = "font.um"
  "std.um"
)

type Font* = interface {
  validate(): bool
  draw(text: str, pos: th::Vf2, color: uint32, scale: th::fu = 1.0)
  measure(text: str): th::Vf2
}

fn load*(path: str, size: th::fu, filter: f::Filter = .linear): (Font, std::Err) {
  return f::load(path, size, filter)
}

In load, there will be an error because f::Font to Font (interface) is not implicitly converted, the workaround is:

fn load*(path: str, size: th::fu, filter: f::Filter = .linear): (Font, std::Err) {
  font, err := f::load(path, size, filter)
  return font, err
}
vtereshkov commented 1 month ago

In fact, this is not about interfaces:

fn f(): (int, int) {
    return 5, 7
}

fn g(): (int, real) {
    return f()  // Incompatible types { int real } and { int int }
}

fn main() {
    a, b := g()
    printf("%v %v\n", a, b)
}
skejeton commented 1 month ago

interesting