Skip to content

Commit

Permalink
Merge pull request #43005 from chiranSachintha/annotation-issue
Browse files Browse the repository at this point in the history
[Master] Fix annotation values with mapping values panic at runtime for const annotations
  • Loading branch information
chiranSachintha authored Jun 29, 2024
2 parents 6545716 + 379ea34 commit ac3ec4c
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -927,11 +927,11 @@ private boolean populateRecordFields(BLangExpression expr, BConstantSymbol const
return false;
}
keyValuePair.setBType(newType);
if (newType.getKind() != TypeKind.FINITE) {
TypeKind kind = newType.getKind();
if (kind != TypeKind.FINITE) {
constValueMap.get(key).type = newType;
if (newType.getKind() == TypeKind.INTERSECTION) {
exprValueField.setBType(((BIntersectionType) newType).effectiveType);
}
BType type = kind == TypeKind.INTERSECTION ? ((BIntersectionType) newType).effectiveType : newType;
exprValueField.setBType(type);
}

recordType.fields.put(key, createField(newSymbol, newType, key, pos));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,11 @@ public void testServiceRemoteMethodAnnotations() {
BRunUtil.invoke(result, "testServiceRemoteMethodAnnotations");
}

@Test
public void testConstTypeAnnotAccess() {
BRunUtil.invoke(resultOne, "testConstTypeAnnotAccess");
}

@AfterClass
public void tearDown() {
resultOne = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,68 @@ type MedicalNeed record {

};

public type AnnotationRecord record {|
string summary?;
Examples examples?;
|};

public type Examples record {|
map<ExampleItem> response;
|};

public type ExampleItem record {
map<string> headers?;
};

const annotation AnnotationRecord annot on type;

@annot {
examples: {
response: {}
}
}
type Employee record {|
int id;
string name;
|};

public type AnnotationRecord1 record {|
string summary?;
ExamplesReference examples?;
|};

type ExamplesReference Examples;

const annotation AnnotationRecord1 annot1 on type;

@annot1 {
examples: {
response: {}
}
}
type Student record {|
int id;
string name;
|};

function testConstTypeAnnotAccess() {
Employee employee = {id: 1, name: "chirans"};
typedesc<any> t = typeof employee;
AnnotationRecord? annot = t.@annot;
assertTrue(annot is AnnotationRecord);
AnnotationRecord config = <AnnotationRecord> annot;
assertEquality({"response":{}}, config.examples);
assertTrue(config.examples is readonly);

Student student = {id: 2, name: "sachintha"};
typedesc<any> s = typeof student;
AnnotationRecord1? annot1 = s.@annot1;
assertTrue(annot1 is AnnotationRecord1);
AnnotationRecord1 config1 = <AnnotationRecord1> annot1;
assertEquality({"response":{}}, config1.examples);
assertTrue(config1.examples is readonly);
}

function testListExprInConstAnnot() {
EntityConfig? annot = MedicalNeed.@Entity;
assertTrue(annot is EntityConfig);
Expand Down

0 comments on commit ac3ec4c

Please sign in to comment.