selfhost: Add bindings on is operator for enum variants
In codegen, it will de-sugar this:
function main() {
let foo = Foo::Bar(5)
let baz = Foo::Baz(m: "Hello")
if foo is Bar(n) {
if baz is Baz(m: different) {
println("{} {}", n, different)
}
}
}
Into this:
ErrorOr<int> main(Array<String>)
{
{
const Foo foo = typename Foo::Bar(static_cast<i64>(5LL));
const Foo baz = typename Foo::Baz(String("Hello"));
if ((foo).has<Foo::Bar>()) {
const i64 n = (foo.get<Foo::Bar>()).value;
if ((baz).has<Foo::Baz>()) {
const String different = (baz.get<Foo::Baz>()).m;
outln(String("{} {}"), n, different);
}
}
}
return 0;
}
@adleroliveira - couple thoughts:
Can you drop the Foo::?:
function main() {
let foo = Foo::Bar(5)
let baz = Foo::Baz(m: "Hello")
if foo is Bar(n) {
if baz is Baz(m: different) {
println("{} {}", n, different)
}
}
}
also, can you add a test for the case I was wondering about the other day where it's compound in the if?
if foo is Bar(n) and n > 4 { ... }
@adleroliveira - couple thoughts:
Can you drop the
Foo::?:function main() { let foo = Foo::Bar(5) let baz = Foo::Baz(m: "Hello") if foo is Bar(n) { if baz is Baz(m: different) { println("{} {}", n, different) } } }also, can you add a test for the case I was wondering about the other day where it's compound in the
if?if foo is Bar(n) and n > 4 { ... }
You can now use if foo is Foo::Bar(x) as well as if foo is Bar(x)
The chaining of bindings will go in a separate PR.
Hello!
One or more of the commit messages in this PR do not match the Jakt code submission policy, please check the lint_commits CI job for more details on which commits were flagged and why.
Please do not close this PR and open another, instead modify your commit message(s) with git commit --amend and force push those changes to update this PR.
Please squash selfhost: Remove .ninja_log from staged commit into the relevant preceding commit.
Please squash
selfhost: Remove .ninja_log from staged commitinto the relevant preceding commit.
awesomekling done :)
Closing this one and opening a new one with total refactor