Lifetime Boundaries #411
-
Hey, union a() {
print(x
}
union b() {
const const x<-50> = 2!
}
union c() {
const const x<-50> = 3!
}
a()!
b()!
a()!
c()!
a()! What would this code print? If not, are variables limited to their scope, or are lifetimes transferred outside? union a(b) {
print(b)! // Second line
print(b)! // Third line - would this error?
}
const const x<2> = 2!
a(x)! // First line
print(x)! // Second line
print(x)! // Third line - this definitely errors |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
From my other issue here I would assume that lifetimes just denote which lines in the scope are valid (so the first example would error and the second example would error at the last print statement) but I'm not very sure about this. |
Beta Was this translation helpful? Give feedback.
-
I've realized that the language would likely be impossible (logically impossible, not just difficult) to implement if my previous assumption were false, so I'm just going to assume the aforementioned assumption is correct. |
Beta Was this translation helpful? Give feedback.
-
Variables are scoped to their scope. In production, it would print this:
Numbers are passed by value:
|
Beta Was this translation helpful? Give feedback.
Variables are scoped to their scope. In production, it would print this:
Numbers are passed by value: