umka-lang icon indicating copy to clipboard operation
umka-lang copied to clipboard

Allow implicit type casts for expression list items

Open ske2004 opened this issue 1 year ago • 2 comments

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
}

ske2004 avatar Jun 06 '24 12:06 ske2004

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)
}

vtereshkov avatar Jun 06 '24 15:06 vtereshkov

interesting

ske2004 avatar Jun 06 '24 16:06 ske2004