Semantic test for type classes

This commit is contained in:
Kamil Śliwak 2023-09-05 19:49:59 +02:00
parent acad00f461
commit 9f7764c215

View File

@ -0,0 +1,65 @@
pragma experimental solidity;
type Cat = word;
type Dog = word;
class A: Animal {
function new() -> A;
function alive(a: A) -> bool;
}
instantiation Cat: Animal {
function new() -> Cat {
let c;
return c;
}
function alive(c: Cat) -> bool {
// TODO: Boolean literals or operators not implemented.
let w;
assembly {
w := 1
}
return bool.abs(w);
}
}
instantiation Dog: Animal {
function new() -> Dog {
let d: Dog;
return d;
}
function alive(d: Dog) -> bool {
let b: bool;
return b;
}
}
contract C {
fallback() external {
let boolResult1: bool;
let boolResult2: bool;
let c: Cat = Animal.new();
boolResult1 = Animal.alive(c);
let d: Dog = Animal.new();
boolResult2 = Animal.alive(d);
let wordResult1 = bool.rep(boolResult1);
let wordResult2 = bool.rep(boolResult2);
assembly {
mstore(0, wordResult1)
mstore(32, wordResult2)
return(0, 64)
}
}
}
// ====
// EVMVersion: >=constantinople
// ====
// compileViaYul: true
// ----
// () -> 1, 0