Skip to content

Commit

Permalink
Merge pull request #42 from ConsenSys/issue_33
Browse files Browse the repository at this point in the history
Fix for Issue #31: Failure with "using for" over address
  • Loading branch information
cd1m0 authored May 5, 2021
2 parents d357ccf + 27076df commit e6ef5b6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
18 changes: 2 additions & 16 deletions src/spec-lang/tc/typecheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1360,28 +1360,14 @@ export function tcMemberAccess(expr: SMemberAccess, ctx: STypingCtx, typeEnv: Ty
if (type) {
return type;
}

throw new SNoField(
`Contract ${baseT.name} doesn't have a function, public state variable or address builtin member ${expr.member}`,
expr,
expr.member
);
}

if (baseT instanceof AddressType) {
const type = BuiltinAddressMembers.get(expr.member);

if (type === undefined) {
throw new SNoField(
`Address type expression ${expr.base.pp()} doesn't have a builtin member ${
expr.member
}`,
expr,
expr.member
);
if (type !== undefined) {
return type;
}

return type;
}

if (
Expand Down
10 changes: 10 additions & 0 deletions test/unit/tc.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ describe("TypeChecker Expression Unit Tests", () => {
function foo(int128 x) public returns (bool) {
return true;
}
function balanceOf(address x) internal pure returns (uint) {
return 123;
}
function balanceOf2(Foo x) internal pure returns (uint) {
return 123;
}
}
library Lib3 {
Expand Down Expand Up @@ -336,6 +344,8 @@ describe("TypeChecker Expression Unit Tests", () => {
["Foo", undefined],
new PointerType(new BytesType(), DataLocation.Storage)
],
["address(0x0).balanceOf()", ["Foo", undefined], new IntType(256, false)],
["this.balanceOf2()", ["Foo", undefined], new IntType(256, false)],
["add(5,5)", ["Foo", undefined], new IntType(64, false)],
["old(5)", ["Foo", "add"], new IntLiteralType()],
["old(sV1)", ["Foo", "add"], new IntType(128, true)],
Expand Down

0 comments on commit e6ef5b6

Please sign in to comment.