-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: do not allow assignments to constants (#682)
- Loading branch information
1 parent
8eb102c
commit 5d470b3
Showing
12 changed files
with
239 additions
and
0 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
10 changes: 10 additions & 0 deletions
10
src/types/stmts-failed/assign-augmented-const-contract.tact
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,10 @@ | ||
primitive Int; | ||
trait BaseTrait { } | ||
|
||
contract Test { | ||
const foo: Int = 42; | ||
|
||
fun bar() { | ||
self.foo += 1 // <-- trying to assign to a constant | ||
} | ||
} |
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,7 @@ | ||
primitive Int; | ||
|
||
const foo: Int = 42; | ||
|
||
fun bar() { | ||
foo += 1 // <-- trying to assign to a constant | ||
} |
14 changes: 14 additions & 0 deletions
14
src/types/stmts-failed/assign-augmented-const-struct-contract.tact
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,14 @@ | ||
primitive Int; | ||
trait BaseTrait { } | ||
|
||
struct Foo {x: Int; y: Int} | ||
|
||
contract Test { | ||
const foo: Foo = Foo {x: 42, y: 43}; | ||
baz: Foo = Foo {x: 42, y: 43}; | ||
|
||
fun bar() { | ||
self.baz.x += 1; // ok | ||
self.foo.y -= 1 // <-- trying to assign to a constant | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/types/stmts-failed/assign-augmented-const-struct-global.tact
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,11 @@ | ||
primitive Int; | ||
|
||
struct Foo {x: Int; y: Int} | ||
|
||
const foo: Foo = Foo {x: 42, y: 43}; | ||
|
||
fun bar() { | ||
let baz: Foo = Foo {x: 42, y: 43}; | ||
baz.x += 1; // ok | ||
foo.y -= 1 // <-- trying to assign to a constant | ||
} |
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,10 @@ | ||
primitive Int; | ||
trait BaseTrait { } | ||
|
||
contract Test { | ||
const foo: Int = 42; | ||
|
||
fun bar() { | ||
self.foo = 43 // <-- trying to assign to a constant | ||
} | ||
} |
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,7 @@ | ||
primitive Int; | ||
|
||
const foo: Int = 42; | ||
|
||
fun bar() { | ||
foo = 43 // <-- trying to assign to a constant | ||
} |
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,14 @@ | ||
primitive Int; | ||
trait BaseTrait { } | ||
|
||
struct Foo {x: Int; y: Int} | ||
|
||
contract Test { | ||
const foo: Foo = Foo {x: 42, y: 43}; | ||
baz: Foo = Foo {x: 42, y: 43}; | ||
|
||
fun bar() { | ||
self.baz.x = 1; // ok | ||
self.foo.y = 42 // <-- trying to assign to a constant | ||
} | ||
} |
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,11 @@ | ||
primitive Int; | ||
|
||
struct Foo {x: Int; y: Int} | ||
|
||
const foo: Foo = Foo {x: 42, y: 43}; | ||
|
||
fun bar() { | ||
let baz: Foo = Foo {x: 42, y: 43}; | ||
baz.x = 1; // ok | ||
foo.y = 42 // <-- trying to assign to a constant | ||
} |
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,11 @@ | ||
primitive Int; | ||
|
||
struct IntWrapper { x: Int } | ||
|
||
extends mutates fun foo(self: IntWrapper) { | ||
self.x = 42 | ||
} | ||
|
||
extends mutates fun bar(self: Int) { | ||
self = 42 | ||
} |