candid icon indicating copy to clipboard operation
candid copied to clipboard

Bug in type inference when parsing textual representation without known types

Open Dfinity-Bjoern opened this issue 6 months ago • 1 comments

My minimal example for reproduction is the following:

decode(encode(vec{ record{ topic = opt variant{DaoCommunitySettings} }; record{ topic = opt variant{SnsFrameworkManagement} }}))

vec {
  record { 338_645_423 = opt variant { 1_138_944_090 } };
  record { 338_645_423 = opt variant { 1_138_944_090 } };
}

This particular example is taken from SNS types, but generally the problem seems to be inferring the type of the variant inside the vec, which seems to default to just using the first.

Dfinity-Bjoern avatar Jun 25 '25 14:06 Dfinity-Bjoern

The issue seems to be related to the fact that we infer the type of vec inner elements only by looking at the first element.

Fixing this can be difficult, as we would need to traverse all the elements of the vec and keep track of all the variants and their values that we encounter.

ilbertt avatar Jun 26 '25 13:06 ilbertt