Some usability issues around `abi` and `Contract`
Below are some examples that should not compile but do. I bundled those together in the same issue because they are somewhat related and there may be others. Whoever takes this on should also think about other corner cases that are not covered below.
Self impl instead of impl ABI for Contract
contract;
abi MyContract {
fn foo();
}
impl Contract { // self impl for a `Contract`?
fn foo() {
}
}
Mismatch in return types
Interestingly this is only a problem for integer types. I still don't think this should compile (Similar playground link)
contract;
abi MyContract {
fn foo() -> u32;
}
impl MyContract for Contract {
fn foo() -> u64 {
0
}
}
Traits in Sway have the same problem btw. The following should not compile but does:
trait T {
fn foo() -> u64;
}
struct S {
x: u64
}
impl T for S {
fn foo() -> u32 {
0
}
}
This also seems to be a problem in this situation which compiles but shouldn't:
contract;
abi MyContract {
fn foo()-> u64;
}
impl Contract {
fn foo() { // No return type here
}
}
Repeated abi declarations:
The following compiles but I don't expect it to:
contract;
abi MyContract {
fn foo() -> u64;
}
abi MyContract {
fn bar() -> u64;
}
Multiple definitions of abi methods
Example:
contract;
abi MyContract {
fn foo() -> u64;
}
impl MyContract for Contract {
fn foo() -> u64 {
0
}
}
impl MyContract for Contract {
fn foo() -> u64 {
0
}
}
Multiple impl blocks for the same type or trait should be allowed but they should not allow redefinition of methods. This applies for ABIs, regular traits, and types.
self inside ABI function signature
ABI function should accept self as the first argument.
contract;
abi MyContract {
fn foo(self);
}
Oh wow, these are quite surprising. OTOH, they aren't since all our tests are written by humans. We should consider using a fuzzer to come up with these sorts of examples.
Edit: #2400
Sorry @anton-trunov I put myself under the assigned section on accident.
Looks like all the tasks are now complete. Closing.