tact-lang / tact

Tact compiler main repository
https://tact-lang.org
MIT License
280 stars 56 forks source link

No error for duplicate trait inheritance #486

Closed byakuren-hijiri closed 1 day ago

byakuren-hijiri commented 3 days ago
import "@stdlib/deploy";
contract SampleTactContract with Deployable, Deployable {
    owner: Address;
    init(owner: Address) {
        self.owner = owner;
    }
}

Expected: a warning or a compilation error because we inherit the Deployable trait twice. Result: Successful compilation.

Should we consider adding a compilation error for that case?

anton-trunov commented 3 days ago

Should we consider adding a compilation error for that case?

yeah, this is definitely a bug

anton-trunov commented 1 day ago

So, I checked and the trait copying algorithm, which inserts trait's entities into the contract, checks if a trait was already processed and ignores it. This is to make sure that multiple trait inheritance from different paths works properly. For example, MyContract

classDiagram
    Fooable <|-- Bazable
    Barable <|-- Bazable
    MyContract <|-- Fooable
    MyContract <|-- Barable

will only inherit the Bazable trait once.

So, it means we need to just process duplicate traits in the immediate inheritance list, as the recursive case is fine and already handled.