Analyze inline assembly variable declarations for invalid or shadowing names.

This commit is contained in:
Daniel Kirchner
2019-11-07 13:04:37 +01:00
parent 30ea41c36d
commit 0556f64722
14 changed files with 154 additions and 3 deletions
@@ -0,0 +1,15 @@
contract C {
function f() public pure {
assembly {
let x_offset := 1
let x_slot := 1
let _offset := 1
let _slot := 1
}
}
}
// ----
// DeclarationError: (79-87): In variable declarations _slot and _offset can not be used as a suffix.
// DeclarationError: (109-115): In variable declarations _slot and _offset can not be used as a suffix.
// DeclarationError: (137-144): In variable declarations _slot and _offset can not be used as a suffix.
// DeclarationError: (166-171): In variable declarations _slot and _offset can not be used as a suffix.
@@ -0,0 +1,9 @@
contract C {
function f(uint a) public pure {
assembly {
let a := 1
}
}
}
// ----
// DeclarationError: (85-86): This declaration shadows a declaration outside the inline assembly block.
@@ -0,0 +1,10 @@
contract C {
uint constant a;
function f() public pure {
assembly {
let a := 1
}
}
}
// ----
// DeclarationError: (100-101): This declaration shadows a declaration outside the inline assembly block.
@@ -0,0 +1,9 @@
contract C {
function f() public pure {
assembly {
let C := 1
}
}
}
// ----
// DeclarationError: (79-80): This declaration shadows a declaration outside the inline assembly block.
@@ -0,0 +1,9 @@
contract C {
function f() public pure {
assembly {
let f := 1
}
}
}
// ----
// DeclarationError: (79-80): This declaration shadows a declaration outside the inline assembly block.
@@ -0,0 +1,10 @@
contract C {
function f() public pure {
uint a;
assembly {
let a := 1
}
}
}
// ----
// DeclarationError: (95-96): This declaration shadows a declaration outside the inline assembly block.
@@ -0,0 +1,18 @@
==== Source: a ====
contract A
{
uint constant a = 42;
}
==== Source: b ====
import {A as b} from "a";
contract B {
function f() public pure {
assembly {
let b := 3
let b.a := 4
}
}
}
// ----
// DeclarationError: (b:105-106): This declaration shadows a declaration outside the inline assembly block.
// DeclarationError: (b:128-131): The prefix of this declaration conflicts with a declaration outside the inline assembly block.
@@ -0,0 +1,15 @@
==== Source: a ====
contract A
{
uint constant a = 42;
}
==== Source: b ====
import {A as b} from "a";
contract B {
function f() public pure {
assembly {
let A := 1
let A.b := 2
}
}
}
@@ -0,0 +1,14 @@
contract D {
uint constant a;
}
contract C {
function f() public pure {
assembly {
let D.a := 1
let D.b := 1 // shadowing the prefix only is also an error
}
}
}
// ----
// DeclarationError: (115-118): The prefix of this declaration conflicts with a declaration outside the inline assembly block.
// DeclarationError: (140-143): The prefix of this declaration conflicts with a declaration outside the inline assembly block.