essential-contributions / pint

Pint, the constraint-based programming language for declarative blockchains
Apache License 2.0
17 stars 3 forks source link

Some potential issues surrounding complex type aliases #586

Open lethalgem opened 5 months ago

lethalgem commented 5 months ago
type myAliasForCast = int;
type myNestedCast = int[4 as myAliasForCast];
type myNestedTuple = int[{2, 1}.0];
type myNestedArray = int[[2, 1][1]];
type complexType = { myNestedCast, myNestedIf }[(2 in {1, 2, 3}) as int];

intent Foo {}

currently results in

// intermediate <<<
// type ::myAliasForCast = int;
// type ::myNestedCast = int[4 as ::myAliasForCast];
// type ::myNestedTuple = int[{2, 1}.0];
// type ::myNestedArray = int[[2, 1][1]];
// type ::complexType = {::myNestedCast, ::myNestedIf}[2 in {1, 2, 3} as int];
// 
// intent ::Foo {
//     type ::myAliasForCast = int;
//     type ::myNestedCast = int[4 as ::myAliasForCast];
//     type ::myNestedTuple = int[1.0]; // issue
//     type ::myNestedArray = int[2[1]]; // issue
//     type ::complexType = {::myNestedCast, ::myNestedIf}[3 as int]; // issue
// }
// >>>

// flattened <<<
// type ::myAliasForCast = int;
// type ::myNestedCast = int[4 as int];
// type ::myNestedTuple = int[{2, 1}.0];
// type ::myNestedArray = int[[2, 1][1]];
// type ::complexType = {::myNestedCast, ::myNestedIf}[2 in {1, 2, 3} as int];
// 
// intent ::Foo {
//     type ::myAliasForCast = int;
//     type ::myNestedCast = int[4 as int];
//     type ::myNestedTuple = int[1.0];
//     type ::myNestedArray = int[2[1]];
//     type ::complexType = {::myNestedCast, ::myNestedIf}[3 as int];
// }
// >>>
mohammadfawaz commented 1 month ago

Not sure exactly what the original error was but for this type does not work:

type complexType = int[2 in {1, 2, 3}];

we get:

Error: compiler internal error: unexpected expression during compile-time evaluation

I think the other type seem fine.

mohammadfawaz commented 1 month ago

I tested this using https://github.com/essential-contributions/pint/pulls/857