argotorg / solcore

experimental solidity compiler
13 stars 1 forks source link

Typechecker does not properly verify instance method types #12

Closed mbenke closed 1 month ago

mbenke commented 2 months ago

Consider

class a:Enum {
    function fromEnum(x:a) -> Word;
  }

  data Color = R | G | B

instance Color : Enum {
  function fromEnum(c) {
    match c {
      | R => return 1;
      | G => return 2;
      | B => return 3;
    };
  }
}

data Bool = False | True

instance Bool : Enum {
  function fromEnum(b) {
      match b {
      | R => return 0;
      | G => return 1;
      };
  }
}

contract  BadInstance {
  function main() { return fromEnum(True);}
}

EXPECTED: the Bool : Enum instance should be rejected as itsfromEnum method has type Color -> Word rather than Bool -> Word.

ACTUAL: typechecker accepts the program (and later phases make a mess, because the well-typedness assumption is false)

rodrigogribeiro commented 1 month ago

Fixed in main.