Incorrect warnings?

Can anyone let me know if the compiler gives me incorrect warnings:

var s: String = ""
var t: Bool = True
if t:
    s = "s is used"
else:
    s = "s is also used"
print(s)
$ mojo life.mojo
life.mojo:2:21: warning: assignment to 's' was never used; assign to '_' instead?
    var s: String = ""
                    ^
s is used

It’s because you initialize and then reassign s right away.

var s: String
var t: Bool = True
if t:
    s = "s is used"
else:
    s = "s is also used"
print(s)

Will remove the warnings.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.