Timothy Wong
06/28/2019, 7:08 PMvar local variables - if the variable is not modified between the check and the usage, is not captured in a lambda that modifies it, and is not a local delegated property;
karelpeeters
06/28/2019, 7:12 PMvar
itself, not its properties. Right below that it says:
var properties - never (because the variable can be modified at any time by other code).
Shawn
06/28/2019, 7:14 PMkarelpeeters
06/28/2019, 7:15 PMShawn
06/28/2019, 7:15 PMfun test() {
var node = createBin()
if (node is BinaryOp) {
var left = node.left
var right = node.right
if (left is IntLit && right is IntLit) {
right.token.value // unresolved reference: value
val right = node.right as IntLit
right.token.value // no problem
}
}
}
this works, and I feel like it shouldn’t if that were the caseTimothy Wong
06/28/2019, 7:15 PMstreetsofboston
06/28/2019, 7:16 PMif(node is BinaryOp) {
val l = node.left
val r = node.right
if(l is IntLit && r is IntLit) {
r.token.value
l.token.value
}
}
karelpeeters
06/28/2019, 7:19 PMTimothy Wong
06/28/2019, 7:20 PMkarelpeeters
06/28/2019, 7:20 PMShawn
06/28/2019, 7:20 PMstreetsofboston
06/28/2019, 7:24 PMnode.left
(and same for node.right
) in a temporary variable l
or not should not matter….