Skip to content

Commit

Permalink
Address review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
ushirask committed Aug 9, 2023
1 parent 7000cfb commit 27f7dc0
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,7 @@ public void visit(BLangLiteral literalExpr, AnalyzerData data) {
}

if (literalType.tag == TypeTags.BYTE_ARRAY) {
data.resultType = rewriteByteArrayLiteral(literalExpr, data);
return;
literalType = rewriteByteArrayLiteral(literalExpr, data);
}

if (literalExpr.isFiniteContext) {
Expand All @@ -278,8 +277,8 @@ private BType rewriteByteArrayLiteral(BLangLiteral literalExpr, AnalyzerData dat

List<BType> memberTypes = new ArrayList<>();
for (byte b : values) {
memberTypes.add(getFiniteType(Byte.toUnsignedInt(b), data.constantSymbol, literalExpr.pos,
symTable.byteType));
memberTypes.add(getFiniteType(Byte.toUnsignedLong(b), data.constantSymbol, literalExpr.pos,
symTable.intType));
}

BType expType = Types.getReferredType(data.expType);
Expand All @@ -288,11 +287,6 @@ private BType rewriteByteArrayLiteral(BLangLiteral literalExpr, AnalyzerData dat
((BArrayType) expType).state = BArrayState.CLOSED;
}

BArrayType arrayType = new BArrayType(symTable.byteType, null, values.length, BArrayState.CLOSED);
if (types.typeIncompatible(literalExpr.pos, arrayType, expType)) {
return symTable.semanticError;
}

return createNewTupleType(literalExpr.pos, memberTypes, data);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,11 @@ public void testConstantAssignmentNegative() {
BAssertUtil.validateError(negativeCompileResult, i++, "missing non-defaultable required record field 'a'",
26, 14);
BAssertUtil.validateError(negativeCompileResult, i++,
"incompatible types: expected 'string[]', found 'byte[2]'", 28, 20);
"incompatible types: expected 'string[]', found '[170,187]'", 28, 20);
BAssertUtil.validateError(negativeCompileResult, i++,
"incompatible types: expected '[string,int]', found '[170,187]'", 30, 26);
BAssertUtil.validateError(negativeCompileResult, i++,
"incompatible types: expected '[170]', found '[170,187]'", 32, 19);
Assert.assertEquals(negativeCompileResult.getErrorCount(), i);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,7 @@ const record{|X x; int i;|} F2 = {x: {b : "a"}, i: 1, c: 2};
const X F3 = {b : "b"};

const string[] Y = base16 `aabb`;

const [string, int] Z = base16 `aabb`;

const [170] Z1 = base16 `aabb`;
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,9 @@ const data6 = base64 `ABCD pqrs`;
const byte[*] data7 = base16 `55 EE 66`;
const byte[*] data8 = base64 `ABCD pqrs`;

const [170] data9 = base16 `aa`;
const [170, 187] data10 = base16 `aabb`;

function testConstByteArrLiteral() {
assertEqual(data1.length(), 3);
assertEqual(data2.length(), 6);
Expand Down Expand Up @@ -362,6 +365,9 @@ function testConstByteArrLiteral() {
assertEqual(data8.length(), 6);
assertEqual(data7[1], 0xEE);
assertEqual(data8[2], 131);

assertEqual(data9[0], 170);
assertEqual(data10[1], 187);
}

function assertInvalidUpdateError(error? res, string expectedDetailMessage) {
Expand Down

0 comments on commit 27f7dc0

Please sign in to comment.