ballerina-platform / ballerina-spec

Ballerina Language and Platform Specifications
Other
167 stars 53 forks source link

Initialization cycle involving defaults in module type definition #1231

Open chiranSachintha opened 1 year ago

chiranSachintha commented 1 year ago

Description: Need to clarify the following scenario. As per the specification, annotations and default values of a type are considered as parts of its typedesc.

type AnnotRecordOne record {|
   string value;
|};

type AnnotRecordTwo record {|
   string value;
|};

annotation AnnotRecordOne annotTwo on type, field;

type FooRecord record {|@annotTwo {value: foo()} string x = "value";|};

function foo() returns string {
    FooRecord r = {};
    return r.x;
}

In the given example, when generating the typedesc for FooRecord, it is necessary to evaluate the foo function. However, to evaluate the foo function, the typedesc of FooRecord is required.

I need to verify whether this scenario is correct or not. If it is incorrect, will we give an error at runtime or compile time? The specification does not mention whether we need to give a cyclic error for this type of scenario during compile time.

jclark commented 1 year ago

This relates to #35.

See specifically https://github.com/ballerina-platform/ballerina-spec/issues/35#issuecomment-1512357879

jclark commented 1 year ago

What this case shows is that we need to distinguish different kinds of usage for module-level types as well as functions.

We can say here that

So we have a cycle, which should be a compile-time error.