mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Semantic test for type classes
This commit is contained in:
parent
acad00f461
commit
9f7764c215
65
test/libsolidity/semanticTests/experimental/type_class.sol
Normal file
65
test/libsolidity/semanticTests/experimental/type_class.sol
Normal 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
|
Loading…
Reference in New Issue
Block a user