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

Type-based lookup in sub-expressions (Was: Can't use color name literals in struct property definitions) #897

Open
jturcotte opened this issue Jan 29, 2022 · 3 comments
Labels
a:compiler Slint compiler internal (not the codegen, not the parser) enhancement New feature or request

Comments

@jturcotte
Copy link
Contributor

struct S := {
    c: color,
}
Demo := Window {
    // OK
    property<color> c: red;
    // OK
    property<S> s1: {c: Colors.rgb(255,0,0)};
    // error: Unknown unqualified identifier 'red'
    property<S> s2: {c: red};
}

https://sixtyfps.io/releases/0.1.6/editor/?snippet=struct+S+%3A%3D+%7B%0A++++c%3A+color%2C%0A%7D%0ADemo+%3A%3D+Window+%7B%0A++++%2F%2F+OK%0A++++property%3Ccolor%3E+c%3A+red%3B%0A++++%2F%2F+OK%0A++++property%3CS%3E+s1%3A+%7Bc%3A+Colors.rgb%28255%2C0%2C0%29%7D%3B%0A++++%2F%2F+error%3A+Unknown+unqualified+identifier+%27red%27%0A++++property%3CS%3E+s2%3A+%7Bc%3A+red%7D%3B%0A%7D%0A

@ogoffart
Copy link
Member

Yes, right now we only do "type-specific" lookup (colors, enums) depending of the type of the property itself.
Ideally we should use type inference and see the actual type of the expression we try to analyse.
We need to fix lookup rules anyway: #273

In the mean time, you can use Colors.red everywhere.

@jturcotte
Copy link
Contributor Author

Would it make sense to write Colors.xyz in the documentation instead to prevent this surprise? I actually didn't know that color literals were defined in the Colors namespace.

I'm stumbled on this but I just noticed that there was also this section in the doc: https://sixtyfps.io/releases/0.1.6/docs/rust/sixtyfps/docs/langref/index.html#colors

@ogoffart ogoffart added a:documentation Improvements or additions to documentation (infrastructure and text itself) (mS,bT) a:compiler Slint compiler internal (not the codegen, not the parser) labels Nov 29, 2022
@ogoffart ogoffart changed the title Can't use color name literals in struct property definitions Type-based lookup in sub-expressions (Was: Can't use color name literals in struct property definitions) Nov 29, 2022
@ogoffart
Copy link
Member

ogoffart commented Apr 20, 2023

Probably we should suggest to use Colors.xyz or EnumName.xyz if xyz is not found and it is the value of some enum.

===> #4397

@ogoffart ogoffart added the diagnostics Suggestions for better diagnostics label Apr 20, 2023
@ogoffart ogoffart added enhancement New feature or request and removed diagnostics Suggestions for better diagnostics a:documentation Improvements or additions to documentation (infrastructure and text itself) (mS,bT) labels Jan 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:compiler Slint compiler internal (not the codegen, not the parser) enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants