Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow implicit type casts for expression list items #402

Open
skejeton opened this issue Jun 6, 2024 · 2 comments
Open

Allow implicit type casts for expression list items #402

skejeton opened this issue Jun 6, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@skejeton
Copy link
Contributor

skejeton commented Jun 6, 2024

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
Copy link
Owner

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 vtereshkov changed the title Auto convert to interface from multiple return values. Allow implicit type casts for expression list items Jun 6, 2024
@vtereshkov vtereshkov added the enhancement New feature or request label Jun 6, 2024
@skejeton
Copy link
Contributor Author

skejeton commented Jun 6, 2024

interesting

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants