solc-typed-ast icon indicating copy to clipboard operation
solc-typed-ast copied to clipboard

Adjust `eq()` to work properly with reserved primitive / elementary types

Open blitz-1306 opened this issue 3 years ago • 0 comments

Description

Consider following case:

eq([types.bool, types.bool], [new BoolType(), new BoolType()])

It actually will return false. However it does not seem to be bug, as it is intended behavior.

Context

We can not reuse types (like types.bool and etc) in InferType.elementaryTypeNameStringToTypeNode() due to eq() will fail when comparing complex types. For example:

function () pure returns (bool, bool)

This is the result of eq()s way to handle recursion via visited cache map and store only one corresponding element.

We can reduce amount of allocations if we find a way fix eq()s behavior. However, we should also consider to not cause much allocations during eq(). One of the ways - do not cache primitive type nodes there.

blitz-1306 avatar Oct 20 '22 06:10 blitz-1306