-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow underscores as unused variable identifiers (#338)
- Loading branch information
Showing
14 changed files
with
323 additions
and
46 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
contract UnderscoreVariableTestContract { | ||
something: Int; | ||
|
||
init() { | ||
self.something = 0; | ||
} | ||
|
||
receive() { | ||
// Nothing to do | ||
} | ||
|
||
fun increaseSomething(): Int { | ||
self.something += 1; | ||
return 123; | ||
} | ||
|
||
get fun test1(): Int { | ||
try { | ||
nativeThrow(1); | ||
} catch (_) { | ||
return 0; | ||
} | ||
return 1; | ||
} | ||
|
||
get fun test2(): Int { | ||
let m: map<Int, Int> = emptyMap(); | ||
m.set(1, 2); | ||
m.set(2, 4); | ||
m.set(3, 6); | ||
let x: Int = 0; | ||
foreach (_, v in m) { | ||
x += v; | ||
} | ||
return x; | ||
} | ||
|
||
get fun test3(): Int { | ||
let m: map<Int, Int> = emptyMap(); | ||
m.set(1, 2); | ||
m.set(2, 4); | ||
m.set(3, 6); | ||
let x: Int = 0; | ||
foreach (k, _ in m) { | ||
x += k; | ||
} | ||
return x; | ||
} | ||
|
||
get fun test4(): Int { | ||
let _: Int = self.increaseSomething(); | ||
let _: Int = self.increaseSomething(); | ||
let _ = self.increaseSomething(); | ||
let _ = self.increaseSomething(); | ||
return self.something; | ||
} | ||
} |
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,26 @@ | ||
import { toNano } from "@ton/core"; | ||
import { ContractSystem } from "@tact-lang/emulator"; | ||
import { __DANGER_resetNodeId } from "../../grammar/ast"; | ||
import { UnderscoreVariableTestContract } from "./contracts/output/underscore-variable_UnderscoreVariableTestContract"; | ||
|
||
describe("underscore-variable", () => { | ||
beforeEach(() => { | ||
__DANGER_resetNodeId(); | ||
}); | ||
it("should implement underscore variables correctly", async () => { | ||
// Init | ||
const system = await ContractSystem.create(); | ||
const treasure = system.treasure("treasure"); | ||
const contract = system.open( | ||
await UnderscoreVariableTestContract.fromInit(), | ||
); | ||
await contract.send(treasure, { value: toNano("10") }, null); | ||
await system.run(); | ||
|
||
// Check methods | ||
expect(await contract.getTest1()).toEqual(0n); | ||
expect(await contract.getTest2()).toEqual(12n); | ||
expect(await contract.getTest3()).toEqual(6n); | ||
expect(await contract.getTest4()).toEqual(4n); | ||
}); | ||
}); |
Oops, something went wrong.