[swift-dev] AST – Understanding @lvalue

Tim Bodeit swift-dev at timbodeit.de
Tue May 24 11:48:45 CDT 2016


I couldn’t find any documentation about lvalues in Swift. Can anybody give me a short explanation of what exactly an lvalue is?

In C++ all variables, including those marked with the const modifier seem to be lvalues. It seems to me, that this is not the case for let constants in Swift.

I compared the output of swiftc -dump-ast for 
let i = 42
let j = i+1
and
var i = 42
let j = i+1

Where i was respectively accessed as:

(declref_expr type='Int' location=lvaluetest.swift:2:9 range=[lvaluetest.swift:2:9 - line:2:9] decl=lvaluetest.(file).i at lvaluetest.swift:1:5 direct_to_storage specialized=no)

(load_expr implicit type='Int' location=lvaluetest.swift:2:9 range=[lvaluetest.swift:2:9 - line:2:9]
  (declref_expr type='@lvalue Int' accessKind=read location=lvaluetest.swift:2:9 range=[lvaluetest.swift:2:9 - line:2:9] decl=lvaluetest.(file).i at lvaluetest.swift:1:5 direct_to_storage specialized=no))

Is my assumption correct, that let constants are not lvalues?

Cheers,

Tim
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-dev/attachments/20160524/4c514295/attachment.html>


More information about the swift-dev mailing list