-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
definite assignment analysis for let (#21024)
* draft for let daa * patch * fixes bugs * errors for global let variable reassignments * checkpoint * out param accepts let * add more tests * add documentation * merge tests
- Loading branch information
Showing
9 changed files
with
144 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{.experimental: "strictDefs".} | ||
|
||
proc bar(x: out string) = | ||
x = "abc" | ||
|
||
proc foo() = | ||
block: | ||
let x: string | ||
if true: | ||
x = "abc" | ||
else: | ||
x = "def" | ||
doAssert x == "abc" | ||
block: | ||
let y: string | ||
bar(y) | ||
doAssert y == "abc" | ||
block: | ||
let x: string | ||
if true: | ||
x = "abc" | ||
discard "abc" | ||
else: | ||
x = "def" | ||
discard "def" | ||
doAssert x == "abc" | ||
block: # | ||
let x: int | ||
block: # | ||
let x: float | ||
x = 1.234 | ||
doAssert x == 1.234 | ||
static: foo() | ||
foo() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
discard """ | ||
errormsg: "'let' symbol requires an initialization" | ||
""" | ||
|
||
let x: int |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
discard """ | ||
cmd: "nim check $file" | ||
action: "reject" | ||
nimout: ''' | ||
tlet_uninit3.nim(13, 5) Error: 'let' symbol requires an initialization | ||
tlet_uninit3.nim(19, 5) Error: 'x' cannot be assigned to | ||
tlet_uninit3.nim(23, 11) Error: 'let' symbol requires an initialization | ||
''' | ||
""" | ||
|
||
{.experimental: "strictDefs".} | ||
|
||
let global {.used.}: int | ||
|
||
proc foo() = | ||
block: | ||
let x: int | ||
x = 13 | ||
x = 14 | ||
|
||
block: | ||
let x: int | ||
doAssert x == 0 | ||
foo() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
discard """ | ||
errormsg: "type mismatch: got <string>" | ||
""" | ||
|
||
{.experimental: "strictDefs".} | ||
|
||
proc foo(x: var string) = | ||
echo x | ||
|
||
proc bar() = | ||
let x: string | ||
foo(x) |