diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/TypeChecker.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/TypeChecker.java index 944d381af4a2..ebf616221d13 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/TypeChecker.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/TypeChecker.java @@ -501,12 +501,13 @@ private void checkXMLNamespacePrefixes(List filters, Anal } private int getPreferredMemberTypeTag(BFiniteType finiteType) { - for (BLangExpression valueExpr : finiteType.getValueSpace()) { - int typeTag = Types.getImpliedType(valueExpr.getBType()).tag; - if (typeTag > TypeTags.DECIMAL) { - continue; - } - for (int i = TypeTags.INT; i <= TypeTags.DECIMAL; i++) { + for (int i = TypeTags.INT; i <= TypeTags.DECIMAL; i++) { + for (BLangExpression valueExpr : finiteType.getValueSpace()) { + int typeTag = Types.getImpliedType(valueExpr.getBType()).tag; + if (typeTag > TypeTags.DECIMAL) { + continue; + } + if (typeTag == i) { return i; } @@ -535,21 +536,24 @@ private BType getFiniteTypeMatchWithIntType(BLangLiteral literalExpr, BFiniteTyp } private BType getFiniteTypeMatchWithIntLiteral(BLangLiteral literalExpr, BFiniteType finiteType, - Object literalValue, AnalyzerData data) { + Object literalValue, BType compatibleType, AnalyzerData data) { BType intLiteralType = getFiniteTypeMatchWithIntType(literalExpr, finiteType, data); if (intLiteralType != symTable.noType) { return intLiteralType; } + int typeTag = getPreferredMemberTypeTag(finiteType); if (typeTag == TypeTags.NONE) { return symTable.intType; } + if (literalAssignableToFiniteType(literalExpr, finiteType, typeTag)) { BType type = symTable.getTypeFromTag(typeTag); setLiteralValueForFiniteType(literalExpr, type, data); literalExpr.value = String.valueOf(literalValue); return type; } + // Handle out of range ints if (literalValue instanceof Double) { return symTable.floatType; @@ -557,7 +561,10 @@ private BType getFiniteTypeMatchWithIntLiteral(BLangLiteral literalExpr, BFinite if (literalValue instanceof String) { return symTable.decimalType; } - return symTable.intType; + if (compatibleType.tag == TypeTags.BYTE) { + return symTable.intType; + } + return compatibleType; } private BType silentIntTypeCheck(BLangLiteral literalExpr, Object literalValue, BType expType, @@ -580,15 +587,23 @@ private BType silentIntTypeCheck(BLangLiteral literalExpr, Object literalValue, } private BType silentCompatibleLiteralTypeCheck(BFiniteType finiteType, BLangLiteral literalExpr, - Object literalValue, AnalyzerData data) { - BType resIntType = symTable.semanticError; + Object literalValue, AnalyzerData data) { + BType resIntegerLiteralType = symTable.semanticError; + List compatibleTypes = new ArrayList<>(); for (BLangExpression valueExpr : finiteType.getValueSpace()) { - resIntType = silentIntTypeCheck(literalExpr, literalValue, valueExpr.getBType(), data); - if (resIntType != symTable.semanticError) { - return resIntType; + resIntegerLiteralType = silentIntTypeCheck(literalExpr, literalValue, valueExpr.getBType(), data); + if (resIntegerLiteralType != symTable.semanticError) { + compatibleTypes.add(resIntegerLiteralType); } } - return resIntType; + for (int i = TypeTags.INT; i <= TypeTags.DECIMAL; i++) { + for (BType type: compatibleTypes) { + if (Types.getReferredType(type).tag == i) { + return type; + } + } + } + return resIntegerLiteralType; } private BType checkIfOutOfRangeAndReturnType(BFiniteType finiteType, BLangLiteral literalExpr, Object literalValue, @@ -633,7 +648,7 @@ public BType getIntegerLiteralType(BLangLiteral literalExpr, Object literalValue if (compatibleType == symTable.semanticError) { return compatibleType; } else { - return getFiniteTypeMatchWithIntLiteral(literalExpr, finiteType, literalValue, data); + return getFiniteTypeMatchWithIntLiteral(literalExpr, finiteType, literalValue, compatibleType, data); } } else if (expectedType.tag == TypeTags.UNION) { BUnionType expectedUnionType = (BUnionType) expectedType; @@ -749,12 +764,29 @@ public BType getTypeOfDecimalFloatingPointLiteral(BLangLiteral literalExpr, Obje } else if (expectedType.tag == TypeTags.FINITE) { BFiniteType finiteType = (BFiniteType) expectedType; for (int tag = TypeTags.FLOAT; tag <= TypeTags.DECIMAL; tag++) { - if (literalAssignableToFiniteType(literalExpr, finiteType, tag)) { - BType valueType = setLiteralValueAndGetType(literalExpr, symTable.getTypeFromTag(tag), data); - setLiteralValueForFiniteType(literalExpr, valueType, data); - return valueType; + BType literalValueType = null; + for (BLangExpression valueExpr : finiteType.getValueSpace()) { + if (valueExpr.getBType().tag == tag) { + if (types.checkLiteralAssignabilityBasedOnType((BLangLiteral) valueExpr, literalExpr)) { + BType valueType = setLiteralValueAndGetType(literalExpr, + symTable.getTypeFromTag(tag), data); + setLiteralValueForFiniteType(literalExpr, valueType, data); + return valueType; + } + literalValueType = valueExpr.getBType(); + } + } + if (literalValueType != null) { + return literalValueType; } } + return literalExpr.getBType(); + } else if (expectedType.tag == TypeTags.FLOAT) { + if (!types.validateFloatLiteral(literalExpr.pos, numericLiteral)) { + data.resultType = symTable.semanticError; + return symTable.semanticError; + } + return symTable.floatType; } else if (expectedType.tag == TypeTags.UNION) { BUnionType unionType = (BUnionType) expectedType; for (int tag = TypeTags.FLOAT; tag <= TypeTags.DECIMAL; tag++) { @@ -913,6 +945,9 @@ private BType getTypeMatchingFloatOrDecimal(BType finiteType, List member } } } + if (finiteType.tag == TypeTags.FINITE) { + return checkIfOutOfRangeAndReturnType((BFiniteType) finiteType, literalExpr, literalExpr.value, data); + } return symTable.intType; } @@ -934,7 +969,7 @@ private BType getAndSetAssignableUnionMember(BLangLiteral literalExpr, BUnionTyp BType finiteType = getFiniteTypeWithValuesOfSingleType(expType, desiredType); if (finiteType != symTable.semanticError) { BType setType = setLiteralValueAndGetType(literalExpr, finiteType, data); - if (literalExpr.isFiniteContext) { + if (setType != symTable.semanticError) { // i.e., a match was found for a finite type return setType; } diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/bala/constant/SimpleConstantBalaNegativeTests.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/bala/constant/SimpleConstantBalaNegativeTests.java index e979e5695986..6ddbe175b080 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/bala/constant/SimpleConstantBalaNegativeTests.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/bala/constant/SimpleConstantBalaNegativeTests.java @@ -57,7 +57,7 @@ public void testNegative() { BAssertUtil.validateError(compileResult, i++, "incompatible types: expected 'FloatTypeWithoutType'," + " found 'float'", offset += 7, 30); BAssertUtil.validateError(compileResult, i++, "incompatible types: expected 'DecimalTypeWithType'," + - " found 'float'", offset += 9, 29); + " found 'decimal'", offset += 9, 29); BAssertUtil.validateError(compileResult, i++, "incompatible types: expected 'StringTypeWithType'," + " found 'string'", offset += 9, 28); BAssertUtil.validateError(compileResult, i++, "incompatible types: expected 'StringTypeWithoutType'," + diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/bala/literals/NumericLiteralNegativeTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/bala/literals/NumericLiteralNegativeTest.java new file mode 100644 index 000000000000..0233559a28e6 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/bala/literals/NumericLiteralNegativeTest.java @@ -0,0 +1,126 @@ +/* + * Copyright (c) 2023, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.ballerinalang.test.bala.literals; + +import org.ballerinalang.test.BAssertUtil; +import org.ballerinalang.test.BCompileUtil; +import org.ballerinalang.test.CompileResult; +import org.testng.Assert; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * Negative test cases for numeric literals in ballerina. + */ +public class NumericLiteralNegativeTest { + private CompileResult negativeResult; + + @BeforeClass + public void setup() { + BCompileUtil.compileAndCacheBala("test-src/bala/test_projects/test_numeric_literals"); + negativeResult = BCompileUtil + .compile("test-src/bala/test_bala/literals/test_numeric_literal_negative_test.bal"); + } + + @Test(description = "Test numeric literal assignment statement with errors") + public void testNumericLiteralAssignmentNegativeCases() { + int index = 0; + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'numericliteral/testproject:0.1.0:Foo', found 'float'", 20, 21); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'numericliteral/testproject:0.1.0:Foo', found 'float'", 23, 21); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'numericliteral/testproject:0.1.0:Foo', found 'float'", 24, 21); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'numericliteral/testproject:0.1.0:Foo', found 'float'", 26, 21); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'numericliteral/testproject:0.1.0:Foo2', found 'int'", 30, 22); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'numericliteral/testproject:0.1.0:Foo2', found 'int'", 31, 22); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'numericliteral/testproject:0.1.0:Foo2', found 'int'", 32, 22); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'numericliteral/testproject:0.1.0:Foo2', found 'int'", 33, 22); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'numericliteral/testproject:0.1.0:Foo2', found 'int'", 35, 22); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'numericliteral/testproject:0.1.0:Foo2', found 'float'", 36, 22); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'numericliteral/testproject:0.1.0:Foo3', found 'float'", 39, 22); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'numericliteral/testproject:0.1.0:Foo3', found 'float'", 40, 22); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'numericliteral/testproject:0.1.0:Foo3', found 'float'", 41, 22); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'numericliteral/testproject:0.1.0:Foo3', found 'float'", 42, 22); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'numericliteral/testproject:0.1.0:Foo5', found 'int'", 50, 22); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'numericliteral/testproject:0.1.0:Foo5', found 'float'", 51, 22); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'numericliteral/testproject:0.1.0:Foo5', found 'float'", 52, 22); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'numericliteral/testproject:0.1.0:Foo5', found 'float'", 53, 22); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'numericliteral/testproject:0.1.0:Foo5', found 'float'", 54, 22); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'numericliteral/testproject:0.1.0:Foo5', found 'float'", 56, 22); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'numericliteral/testproject:0.1.0:Foo5', found 'int'", 59, 22); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'numericliteral/testproject:0.1.0:Foo5', found 'float'", 60, 22); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'numericliteral/testproject:0.1.0:Foo5', found 'float'", 61, 22); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'numericliteral/testproject:0.1.0:Foo5', found 'float'", 64, 22); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'numericliteral/testproject:0.1.0:Foo5', found 'int'", 67, 22); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'numericliteral/testproject:0.1.0:Foo5', found 'float'", 68, 22); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'numericliteral/testproject:0.1.0:Foo5', found 'float'", 69, 22); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'numericliteral/testproject:0.1.0:Foo5', found 'float'", 72, 22); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'numericliteral/testproject:0.1.0:Foo5', found 'int'", 75, 22); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'numericliteral/testproject:0.1.0:Foo5', found 'float'", 76, 22); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'numericliteral/testproject:0.1.0:Foo5', found 'float'", 77, 22); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'numericliteral/testproject:0.1.0:Foo5', found 'float'", 78, 22); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'numericliteral/testproject:0.1.0:Foo5', found 'float'", 80, 22); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'numericliteral/testproject:0.1.0:Foo5', found 'float'", 85, 22); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'numericliteral/testproject:0.1.0:Foo5', found 'float'", 86, 22); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'numericliteral/testproject:0.1.0:Foo5', found 'float'", 88, 22); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'numericliteral/testproject:0.1.0:Foo5', found 'float'", 89, 22); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'numericliteral/testproject:0.1.0:Foo5', found 'float'", 90, 22); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'numericliteral/testproject:0.1.0:Foo5', found 'float'", 92, 22); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'numericliteral/testproject:0.1.0:Foo5', found 'int'", 93, 22); + Assert.assertEquals(negativeResult.getErrorCount(), index); + } +} diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/expressions/literals/NumericLiteralAssignmentTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/expressions/literals/NumericLiteralAssignmentTest.java index c52275ae7c14..b7889ab22fe8 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/expressions/literals/NumericLiteralAssignmentTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/expressions/literals/NumericLiteralAssignmentTest.java @@ -18,6 +18,7 @@ package org.ballerinalang.test.expressions.literals; +import org.ballerinalang.test.BAssertUtil; import org.ballerinalang.test.BCompileUtil; import org.ballerinalang.test.BRunUtil; import org.ballerinalang.test.CompileResult; @@ -34,11 +35,13 @@ */ public class NumericLiteralAssignmentTest { - private CompileResult result; + private CompileResult result, negativeResult; @BeforeClass public void setup() { result = BCompileUtil.compile("test-src/expressions/literals/numeric_literal_assignment.bal"); + negativeResult = BCompileUtil + .compile("test-src/expressions/literals/numeric_literal_assignment_negative.bal"); } @Test(dataProvider = "intLiteralsAsSingleNumericTypeFunctions") @@ -146,8 +149,419 @@ public void testFloatLiteralAsIntWithBuiltinUnion() { Assert.assertTrue((Boolean) returns); } + @Test(description = "Test numeric literal assignment statement with errors") + public void testNumericLiteralAssignmentNegativeCases() { + int index = 0; + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'Foo', found 'float'", 24, 13); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'Foo', found 'float'", 27, 13); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'Foo', found 'float'", 28, 13); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'Foo', found 'float'", 30, 13); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'Foo2', found 'int'", 34, 14); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'Foo2', found 'int'", 35, 14); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'Foo2', found 'int'", 36, 14); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'Foo2', found 'int'", 37, 14); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'Foo2', found 'int'", 39, 14); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'Foo2', found 'float'", 40, 14); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'Foo3', found 'float'", 43, 14); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'Foo3', found 'float'", 44, 14); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'Foo3', found 'float'", 45, 14); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'Foo3', found 'float'", 46, 14); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'Foo5', found 'int'", 54, 14); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'Foo5', found 'float'", 55, 14); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'Foo5', found 'float'", 56, 14); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'Foo5', found 'float'", 57, 14); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'Foo5', found 'float'", 58, 14); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'Foo5', found 'float'", 60, 14); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'Foo5', found 'int'", 63, 14); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'Foo5', found 'float'", 64, 14); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'Foo5', found 'float'", 65, 14); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'Foo5', found 'float'", 68, 14); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'Foo5', found 'int'", 71, 14); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'Foo5', found 'float'", 72, 14); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'Foo5', found 'float'", 73, 14); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'Foo5', found 'float'", 76, 14); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'Foo5', found 'int'", 79, 14); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'Foo5', found 'float'", 80, 14); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'Foo5', found 'float'", 81, 14); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'Foo5', found 'float'", 82, 14); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'Foo5', found 'float'", 84, 14); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'Foo5', found 'float'", 89, 14); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'Foo5', found 'float'", 90, 14); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'Foo5', found 'float'", 92, 14); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'Foo5', found 'float'", 93, 14); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'Foo5', found 'float'", 94, 14); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'Foo5', found 'float'", 96, 14); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'Foo5', found 'int'", 97, 14); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'(decimal|4d)', found 'float'", 104, 20); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'(decimal|4d)', found 'float'", 109, 20); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'(decimal|4d)', found 'float'", 111, 20); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'(decimal|2f)', found 'float'", 121, 20); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'(decimal|2f)', found 'float'", 122, 20); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'(decimal|2f)', found 'float'", 124, 20); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'(decimal|2f)', found 'float'", 127, 20); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'(decimal|2f)', found 'float'", 128, 20); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'(decimal|2f)', found 'float'", 131, 20); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'(decimal|3.0f)', found 'float'", 133, 21); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'(decimal|3.0f)', found 'float'", 134, 21); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'(decimal|3.0f)', found 'float'", 136, 21); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'(decimal|3.0f)', found 'float'", 139, 21); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'(decimal|3.0f)', found 'float'", 140, 21); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'(decimal|3.0f)', found 'float'", 143, 21); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'(decimal|1)', found 'float'", 148, 19); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'(decimal|1)', found 'int'", 150, 19); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'(decimal|1)', found 'float'", 153, 19); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'(decimal|1)', found 'float'", 155, 19); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'(decimal|byte)', found 'float'", 160, 22); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'(decimal|2.1f)', found 'float'", 162, 21); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'(decimal|2.1f)', found 'float'", 163, 21); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'(decimal|2.1f)', found 'float'", 165, 21); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'(float|4d)', found 'decimal'", 176, 18); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'(float|4d)', found 'decimal'", 179, 18); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'4d|2f', found 'float'", 182, 15); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'4d|2f', found 'float'", 183, 15); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'4d|2f', found 'float'", 184, 15); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'4d|2f', found 'float'", 185, 15); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'4d|2f', found 'float'", 186, 15); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'4d|2f', found 'float'", 188, 15); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'4d|2f', found 'decimal'", 189, 15); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'4d|2f', found 'float'", 192, 15); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'4d|2f', found 'float'", 193, 15); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'4d|2f', found 'decimal'", 195, 15); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'4d|2f', found 'float'", 196, 15); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'4d|2f', found 'decimal'", 197, 15); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'4d|3.0f', found 'float'", 198, 16); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'4d|3.0f', found 'float'", 199, 16); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'4d|3.0f', found 'float'", 200, 16); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'4d|3.0f', found 'float'", 201, 16); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'4d|3.0f', found 'float'", 202, 16); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'4d|3.0f', found 'float'", 204, 16); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'4d|3.0f', found 'decimal'", 205, 16); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'4d|3.0f', found 'float'", 208, 16); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'4d|3.0f', found 'float'", 209, 16); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'4d|3.0f', found 'decimal'", 211, 16); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'4d|3.0f', found 'float'", 212, 16); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'4d|3.0f', found 'decimal'", 213, 16); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'4d|1', found 'int'", 214, 14); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'4d|1', found 'decimal'", 216, 14); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'4d|1', found 'decimal'", 217, 14); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'4d|1', found 'float'", 218, 14); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'4d|1', found 'float'", 220, 14); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'4d|1', found 'decimal'", 221, 14); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'4d|1', found 'int'", 223, 14); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'4d|1', found 'decimal'", 224, 14); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'4d|1', found 'decimal'", 225, 14); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'4d|1', found 'float'", 226, 14); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'4d|1', found 'decimal'", 227, 14); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'4d|1', found 'float'", 228, 14); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'4d|1', found 'decimal'", 229, 14); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'(byte|4d)', found 'decimal'", 233, 17); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'(byte|4d)', found 'decimal'", 234, 17); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'(byte|4d)', found 'float'", 235, 17); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'(byte|4d)', found 'float'", 237, 17); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'(byte|4d)', found 'decimal'", 238, 17); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'4d|2.1f', found 'float'", 240, 16); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'4d|2.1f', found 'float'", 241, 16); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'4d|2.1f', found 'float'", 242, 16); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'4d|2.1f', found 'float'", 243, 16); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'4d|2.1f', found 'float'", 244, 16); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'4d|2.1f', found 'float'", 246, 16); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'4d|2.1f', found 'decimal'", 247, 16); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'4d|2.1f', found 'decimal'", 250, 16); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'(float|2f)', found 'decimal'", 253, 18); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'(float|2f)', found 'decimal'", 260, 18); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'(float|2f)', found 'decimal'", 262, 18); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'(float|3.0f)', found 'decimal'", 265, 19); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'(float|3.0f)', found 'decimal'", 272, 19); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'(float|3.0f)', found 'decimal'", 274, 19); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'(float|1)', found 'decimal'", 277, 17); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'(float|1)', found 'int'", 280, 17); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'(float|1)', found 'decimal'", 284, 17); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'(float|1)', found 'decimal'", 286, 17); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'(float|byte)', found 'decimal'", 289, 20); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'(float|2.1f)', found 'decimal'", 294, 19); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'(float|2.1f)', found 'decimal'", 298, 19); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'2f|3.0f', found 'float'", 301, 16); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'2f|3.0f', found 'float'", 302, 16); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'2f|3.0f', found 'decimal'", 304, 16); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'2f|3.0f', found 'float'", 305, 16); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'2f|3.0f', found 'decimal'", 306, 16); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'2f|3.0f', found 'float'", 309, 16); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'2f|3.0f', found 'float'", 310, 16); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'2f|3.0f', found 'decimal'", 312, 16); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'2f|3.0f', found 'float'", 313, 16); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'2f|3.0f', found 'decimal'", 314, 16); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'2f|1', found 'int'", 316, 14); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'2f|1', found 'float'", 317, 14); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'2f|1', found 'float'", 318, 14); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'2f|1', found 'decimal'", 320, 14); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'2f|1', found 'float'", 321, 14); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'2f|1', found 'decimal'", 322, 14); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'2f|1', found 'int'", 324, 14); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'2f|1', found 'float'", 325, 14); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'2f|1', found 'float'", 326, 14); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'2f|1', found 'float'", 327, 14); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'2f|1', found 'decimal'", 328, 14); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'2f|1', found 'float'", 329, 14); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'2f|1', found 'decimal'", 330, 14); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'(byte|2f)', found 'float'", 333, 17); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'(byte|2f)', found 'float'", 334, 17); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'(byte|2f)', found 'decimal'", 336, 17); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'(byte|2f)', found 'float'", 337, 17); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'(byte|2f)', found 'decimal'", 338, 17); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'2f|2.1f', found 'float'", 342, 16); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'2f|2.1f', found 'float'", 343, 16); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'2f|2.1f', found 'decimal'", 345, 16); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'2f|2.1f', found 'float'", 346, 16); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'2f|2.1f', found 'decimal'", 347, 16); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'2f|2.1f', found 'decimal'", 350, 16); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'3.0f|1', found 'int'", 352, 15); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'3.0f|1', found 'float'", 353, 15); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'3.0f|1', found 'float'", 354, 15); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'3.0f|1', found 'decimal'", 356, 15); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'3.0f|1', found 'float'", 357, 15); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'3.0f|1', found 'decimal'", 358, 15); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'3.0f|1', found 'int'", 360, 15); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'3.0f|1', found 'float'", 361, 15); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'3.0f|1', found 'float'", 362, 15); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'3.0f|1', found 'float'", 363, 15); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'3.0f|1', found 'decimal'", 364, 15); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'3.0f|1', found 'float'", 365, 15); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'3.0f|1', found 'decimal'", 366, 15); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'(byte|3.0f)', found 'float'", 369, 18); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'(byte|3.0f)', found 'float'", 370, 18); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'(byte|3.0f)', found 'decimal'", 372, 18); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'(byte|3.0f)', found 'float'", 373, 18); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'(byte|3.0f)', found 'decimal'", 374, 18); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'3.0f|2.1f', found 'float'", 378, 17); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'3.0f|2.1f', found 'float'", 379, 17); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'3.0f|2.1f', found 'decimal'", 381, 17); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'3.0f|2.1f', found 'float'", 382, 17); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'3.0f|2.1f', found 'decimal'", 383, 17); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'3.0f|2.1f', found 'decimal'", 386, 17); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'3.0f|2.1f', found 'float'", 387, 17); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'(byte|1)', found 'float'", 390, 16); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'(byte|1)', found 'float'", 391, 16); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'(byte|1)', found 'float'", 392, 16); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'(byte|1)', found 'decimal'", 393, 16); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'(byte|1)', found 'float'", 394, 16); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'(byte|1)', found 'decimal'", 395, 16); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'1|2.1f', found 'int'", 398, 15); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'1|2.1f', found 'float'", 399, 15); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'1|2.1f', found 'float'", 400, 15); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'1|2.1f', found 'float'", 401, 15); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'1|2.1f', found 'decimal'", 402, 15); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'1|2.1f', found 'float'", 403, 15); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'1|2.1f', found 'decimal'", 404, 15); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'1|2.1f', found 'decimal'", 407, 15); + BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + + "'(byte|2.1f)', found 'decimal'", 411, 18); + Assert.assertEquals(negativeResult.getErrorCount(), index); + } + @AfterClass public void tearDown() { result = null; + negativeResult = null; } } diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/constant/ConstantTypeTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/constant/ConstantTypeTest.java index c897b1ea8586..421d2448a720 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/constant/ConstantTypeTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/constant/ConstantTypeTest.java @@ -64,7 +64,9 @@ public void constExpressionSemanticAnalysisNegative() { int i = 0; BAssertUtil.validateError(compileResult1, i++, "incompatible types: expected '3', found 'int'", 34, 15); BAssertUtil.validateError(compileResult1, i++, "incompatible types: expected '3.0f', found 'float'", 35, 15); - BAssertUtil.validateError(compileResult1, i++, "incompatible types: expected '3.0d', found 'float'", 36, 15); + BAssertUtil.validateError(compileResult1, i++, "incompatible types: expected '3.0d', found 'decimal'", 36, 15); + // Activate this after fixing #33889 + // BAssertUtil.validateError(compileResult1, i++, "incompatible types: expected '3', found 'int'", 37, 15); BAssertUtil.validateError(compileResult1, i++, "incompatible types: expected '3', found 'int'", 37, 17); BAssertUtil.validateError(compileResult1, i++, "incompatible types: expected 'false', found 'boolean'", 38, 15); diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/constant/SimpleConstantNegativeTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/constant/SimpleConstantNegativeTest.java index 77329d3f4de2..2a80fdcac758 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/constant/SimpleConstantNegativeTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/constant/SimpleConstantNegativeTest.java @@ -101,7 +101,7 @@ public void testNegative() { BAssertUtil.validateError(compileResult, index++, "incompatible types: expected 'FloatTypeWithoutType', " + "found 'float'", 214, 30); BAssertUtil.validateError(compileResult, index++, "incompatible types: expected 'DecimalTypeWithType', " + - "found 'float'", 225, 29); + "found 'decimal'", 225, 29); BAssertUtil.validateError(compileResult, index++, "incompatible types: expected 'StringTypeWithType', found" + " 'string'", 236, 28); BAssertUtil.validateError(compileResult, index++, "incompatible types: expected 'StringTypeWithoutType', " + diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/finite/FiniteTypeNegativeTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/finite/FiniteTypeNegativeTest.java index 12e34fb7fc04..9048996d7897 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/finite/FiniteTypeNegativeTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/finite/FiniteTypeNegativeTest.java @@ -75,9 +75,13 @@ public void testInvalidLiteralAssignment() { 92, 14); validateError(resultNegativeTwo, i++, "incompatible types: expected 't3', found 'float'", 102, 13); + validateError(resultNegativeTwo, i++, "incompatible types: expected 't3', found 'float'", + 103, 13); + validateError(resultNegativeTwo, i++, "incompatible types: expected '(t|t2)', found 'float'", + 106, 14); validateError(resultNegativeTwo, i++, "incompatible types: expected '(t|t2)', found 'decimal'", 107, 14); - validateError(resultNegativeTwo, i++, "incompatible types: expected 'Foo', found 'int'", + validateError(resultNegativeTwo, i++, "incompatible types: expected 'Foo', found 'float'", 116, 14); validateError(resultNegativeTwo, i++, "incompatible types: expected 'Foo2', found 'int'", 117, 15); @@ -85,11 +89,11 @@ public void testInvalidLiteralAssignment() { 118, 15); validateError(resultNegativeTwo, i++, "incompatible types: expected '\"chiran\"', found 'int'", 119, 18); - validateError(resultNegativeTwo, i++, "incompatible types: expected '1f', found 'int'", + validateError(resultNegativeTwo, i++, "incompatible types: expected '1f', found 'float'", 123, 12); - validateError(resultNegativeTwo, i++, "incompatible types: expected '1.0f', found 'int'", + validateError(resultNegativeTwo, i++, "incompatible types: expected '1.0f', found 'float'", 124, 13); - validateError(resultNegativeTwo, i++, "incompatible types: expected '1.121f', found 'int'", + validateError(resultNegativeTwo, i++, "incompatible types: expected '1.121f', found 'float'", 125, 15); validateError(resultNegativeTwo, i++, "incompatible types: expected '1.2e12f', found 'float'", 126, 16); @@ -99,9 +103,9 @@ public void testInvalidLiteralAssignment() { 128, 18); validateError(resultNegativeTwo, i++, "incompatible types: expected '1.2e12f', found 'decimal'", 129, 16); - validateError(resultNegativeTwo, i++, "incompatible types: expected '2d', found 'int'", + validateError(resultNegativeTwo, i++, "incompatible types: expected '2d', found 'decimal'", 131, 12); - validateError(resultNegativeTwo, i++, "incompatible types: expected '1.2d', found 'float'", + validateError(resultNegativeTwo, i++, "incompatible types: expected '1.2d', found 'decimal'", 132, 14); validateError(resultNegativeTwo, i++, "incompatible types: expected '1.21d', found 'float'", 133, 15); @@ -113,17 +117,17 @@ public void testInvalidLiteralAssignment() { 139, 22); validateError(resultNegativeTwo, i++, "incompatible types: expected '1.2e12f', found 'decimal'", 140, 20); - validateError(resultNegativeTwo, i++, "incompatible types: expected '2d', found 'int'", + validateError(resultNegativeTwo, i++, "incompatible types: expected '2d', found 'decimal'", 142, 16); - validateError(resultNegativeTwo, i++, "incompatible types: expected '1.2d', found 'float'", + validateError(resultNegativeTwo, i++, "incompatible types: expected '1.2d', found 'decimal'", 143, 18); - validateError(resultNegativeTwo, i++, "incompatible types: expected 'Float1', found 'int'", + validateError(resultNegativeTwo, i++, "incompatible types: expected 'Float1', found 'float'", 148, 12); - validateError(resultNegativeTwo, i++, "incompatible types: expected '1f', found 'int'", + validateError(resultNegativeTwo, i++, "incompatible types: expected '1f', found 'float'", 150, 8); - validateError(resultNegativeTwo, i++, "incompatible types: expected '1.0f', found 'int'", + validateError(resultNegativeTwo, i++, "incompatible types: expected '1.0f', found 'float'", 151, 9); - validateError(resultNegativeTwo, i++, "incompatible types: expected '1.121f', found 'int'", + validateError(resultNegativeTwo, i++, "incompatible types: expected '1.121f', found 'float'", 152, 11); validateError(resultNegativeTwo, i++, "incompatible types: expected '1.2e12f', found 'float'", 153, 12); @@ -133,9 +137,9 @@ public void testInvalidLiteralAssignment() { 155, 14); validateError(resultNegativeTwo, i++, "incompatible types: expected '1.2e12f', found 'decimal'", 156, 12); - validateError(resultNegativeTwo, i++, "incompatible types: expected '2d', found 'int'", + validateError(resultNegativeTwo, i++, "incompatible types: expected '2d', found 'decimal'", 158, 8); - validateError(resultNegativeTwo, i++, "incompatible types: expected '1.2d', found 'float'", + validateError(resultNegativeTwo, i++, "incompatible types: expected '1.2d', found 'decimal'", 159, 10); validateError(resultNegativeTwo, i++, "incompatible types: expected '1.21d', found 'float'", 160, 11); @@ -143,19 +147,19 @@ public void testInvalidLiteralAssignment() { "found 'decimal'", 161, 15); validateError(resultNegativeTwo, i++, "incompatible types: expected '12.1d', found 'float'", 162, 11); - validateError(resultNegativeTwo, i++, "incompatible types: expected '2d', found 'int'", + validateError(resultNegativeTwo, i++, "incompatible types: expected '2d', found 'decimal'", 165, 9); - validateError(resultNegativeTwo, i++, "incompatible types: expected '1f', found 'int'", + validateError(resultNegativeTwo, i++, "incompatible types: expected '1f', found 'float'", 165, 12); - validateError(resultNegativeTwo, i++, "incompatible types: expected '0.1219e-1f', found 'int'", + validateError(resultNegativeTwo, i++, "incompatible types: expected '0.1219e-1f', found 'float'", 166, 9); - validateError(resultNegativeTwo, i++, "incompatible types: expected '0x.12p12f', found 'int'", + validateError(resultNegativeTwo, i++, "incompatible types: expected '0x.12p12f', found 'float'", 166, 12); validateError(resultNegativeTwo, i++, "incompatible types: expected '2d', found '1f'", 178, 12); validateError(resultNegativeTwo, i++, "incompatible types: expected '3f', found '2d'", 179, 12); - validateError(resultNegativeTwo, i++, "incompatible types: expected '1f', found 'int'", + validateError(resultNegativeTwo, i++, "incompatible types: expected '1f', found 'float'", 183, 12); validateError(resultNegativeTwo, i++, "incompatible types: expected '2d', found 'string'", 187, 12); @@ -240,9 +244,9 @@ public void testInvalidLiteralAssignment() { validateError(resultNegativeTwo, i++, "unknown type 'InvalidTest1'", 292, 5); validateError(resultNegativeTwo, i++, "incompatible types: expected '1f', found 'float'", 296, 12); - validateError(resultNegativeTwo, i++, "incompatible types: expected '1f', found 'int'", + validateError(resultNegativeTwo, i++, "incompatible types: expected '1f', found 'float'", 297, 12); - Assert.assertEquals(resultNegativeTwo.getErrorCount(), i, "Error count mismatch"); + Assert.assertEquals(resultNegativeTwo.getErrorCount(), i); } @AfterClass diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/floattype/BFloatValueTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/floattype/BFloatValueTest.java index a05ec7b6b230..af8e46c13df6 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/floattype/BFloatValueTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/floattype/BFloatValueTest.java @@ -299,6 +299,7 @@ public void testFloatValuesWithSyntaxErrors() { BAssertUtil.validateError(result, i++, "missing hex number after hex indicator", 18, 23); BAssertUtil.validateError(result, i++, "missing digit after exponent indicator", 18, 26); BAssertUtil.validateError(result, i++, "missing semicolon token", 18, 26); + BAssertUtil.validateError(result, i++, "incompatible types: expected '3ef', found 'float'", 18, 31); BAssertUtil.validateError(result, i++, "missing digit after exponent indicator", 18, 31); BAssertUtil.validateError(result, i++, "missing equal token", 18, 31); BAssertUtil.validateError(result, i++, "missing semicolon token", 18, 34); diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/bala/test_bala/literals/test_numeric_literal_negative_test.bal b/tests/jballerina-unit-test/src/test/resources/test-src/bala/test_bala/literals/test_numeric_literal_negative_test.bal new file mode 100644 index 000000000000..433e85e1d6f7 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/bala/test_bala/literals/test_numeric_literal_negative_test.bal @@ -0,0 +1,94 @@ +// Copyright (c) 2023 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +// +// WSO2 Inc. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +import numericliteral/testproject as module1; + +function testNumericLiteralAssignmentNegative() { + module1:Foo _ = 3; //error: incompatible types: expected 'numericliteral/testproject:0.1.0:Foo', found 'float' + module1:Foo _ = 2; + module1:Foo _ = 2.0; + module1:Foo _ = 1.0; //error: incompatible types: expected 'numericliteral/testproject:0.1.0:Foo', found 'float' + module1:Foo _ = 1.2; //error: incompatible types: expected 'numericliteral/testproject:0.1.0:Foo', found 'float' + module1:Foo _ = 2f; + module1:Foo _ = 3f; //error: incompatible types: expected 'numericliteral/testproject:0.1.0:Foo', found 'float' + module1:Foo _ = 2d; + module1:Foo _ = 3d; + module1:Foo2 _ = 1; + module1:Foo2 _ = 2; // error: incompatible types: expected 'numericliteral/testproject:0.1.0:Foo2', found 'int' + module1:Foo2 _ = 3; // error: incompatible types: expected 'numericliteral/testproject:0.1.0:Foo2', found 'int' + module1:Foo2 _ = 4; // error: incompatible types: expected 'numericliteral/testproject:0.1.0:Foo2', found 'int' + module1:Foo2 _ = 5; // error: incompatible types: expected 'numericliteral/testproject:0.1.0:Foo2', found 'int' + module1:Foo2 _ = 6; + module1:Foo2 _ = 7; // error: incompatible types: expected 'numericliteral/testproject:0.1.0:Foo2', found 'int' + module1:Foo2 _ = 7.1; // error: incompatible types: expected 'numericliteral/testproject:0.1.0:Foo2', found 'float' + module1:Foo3 _ = 2; + module1:Foo3 _ = 3; + module1:Foo3 _ = 4; // error: incompatible types: expected 'numericliteral/testproject:0.1.0:Foo3', found 'float' + module1:Foo3 _ = 5; // error: incompatible types: expected 'numericliteral/testproject:0.1.0:Foo3', found 'float' + module1:Foo3 _ = 7; // error: incompatible types: expected 'numericliteral/testproject:0.1.0:Foo3', found 'float' + module1:Foo3 _ = 7.1; // error: incompatible types: expected 'numericliteral/testproject:0.1.0:Foo3', found 'float' + module1:Foo4 _ = 1; + module1:Foo4 _ = 2; + module1:Foo4 _ = 3; + module1:Foo4 _ = 4; + module1:Foo4 _ = 5; + module1:Foo4 _ = 7; + module1:Foo4 _ = 7.1; + module1:Foo5 _ = 4; //error: incompatible types: expected 'numericliteral/testproject:0.1.0:Foo5', found 'int' + module1:Foo5 _ = 4.0; //error: incompatible types: expected 'numericliteral/testproject:0.1.0:Foo5', found 'float' + module1:Foo5 _ = 5.0; //error: incompatible types: expected 'numericliteral/testproject:0.1.0:Foo5', found 'float' + module1:Foo5 _ = 5.2; //error: incompatible types: expected 'numericliteral/testproject:0.1.0:Foo5', found 'float' + module1:Foo5 _ = 4f; //error: incompatible types: expected 'numericliteral/testproject:0.1.0:Foo5', found 'float' + module1:Foo5 _ = 4d; + module1:Foo5 _ = 5f; //error: incompatible types: expected 'numericliteral/testproject:0.1.0:Foo5', found 'float' + module1:Foo5 _ = 5d; + module1:Foo5 _ = 2.0; + module1:Foo5 _ = 2; //error: incompatible types: expected 'numericliteral/testproject:0.1.0:Foo5', found 'int' + module1:Foo5 _ = 6.0; //error: incompatible types: expected 'numericliteral/testproject:0.1.0:Foo5', found 'float' + module1:Foo5 _ = 6.2; //error: incompatible types: expected 'numericliteral/testproject:0.1.0:Foo5', found 'float' + module1:Foo5 _ = 2f; + module1:Foo5 _ = 2d; + module1:Foo5 _ = 6f; //error: incompatible types: expected 'numericliteral/testproject:0.1.0:Foo5', found 'float' + module1:Foo5 _ = 6d; + module1:Foo5 _ = 3.0; + module1:Foo5 _ = 3; //error: incompatible types: expected 'numericliteral/testproject:0.1.0:Foo5', found 'int' + module1:Foo5 _ = 7.0; //error: incompatible types: expected 'numericliteral/testproject:0.1.0:Foo5', found 'float' + module1:Foo5 _ = 7.2; //error: incompatible types: expected 'numericliteral/testproject:0.1.0:Foo5', found 'float' + module1:Foo5 _ = 3f; + module1:Foo5 _ = 3d; + module1:Foo5 _ = 7f; //error: incompatible types: expected 'numericliteral/testproject:0.1.0:Foo5', found 'float' + module1:Foo5 _ = 7d; + module1:Foo5 _ = 1; + module1:Foo5 _ = 10; //error: incompatible types: expected 'numericliteral/testproject:0.1.0:Foo5', found 'int' + module1:Foo5 _ = 1.0; //error: incompatible types: expected 'numericliteral/testproject:0.1.0:Foo5', found 'float' + module1:Foo5 _ = 1.2; //error: incompatible types: expected 'numericliteral/testproject:0.1.0:Foo5', found 'float' + module1:Foo5 _ = 1f; //error: incompatible types: expected 'numericliteral/testproject:0.1.0:Foo5', found 'float' + module1:Foo5 _ = 1d; + module1:Foo5 _ = 10f; //error: incompatible types: expected 'numericliteral/testproject:0.1.0:Foo5', found 'float' + module1:Foo5 _ = 10d; + module1:Foo5 _ = 2.1; + module1:Foo5 _ = 2.1f; + module1:Foo5 _ = 2.1d; + module1:Foo5 _ = 8.0; //error: incompatible types: expected 'numericliteral/testproject:0.1.0:Foo5', found 'float' + module1:Foo5 _ = 8.2; //error: incompatible types: expected 'numericliteral/testproject:0.1.0:Foo5', found 'float' + module1:Foo5 _ = 8d; + module1:Foo5 _ = 8f; //error: incompatible types: expected 'numericliteral/testproject:0.1.0:Foo5', found 'float' + module1:Foo5 _ = 9.0; //error: incompatible types: expected 'numericliteral/testproject:0.1.0:Foo5', found 'float' + module1:Foo5 _ = 9.2; //error: incompatible types: expected 'numericliteral/testproject:0.1.0:Foo5', found 'float' + module1:Foo5 _ = 9d; + module1:Foo5 _ = 9f; //error: incompatible types: expected 'numericliteral/testproject:0.1.0:Foo5', found 'float' + module1:Foo5 _ = 24; //error: incompatible types: expected 'numericliteral/testproject:0.1.0:Foo5', found 'int' +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/bala/test_projects/test_numeric_literals/Ballerina.toml b/tests/jballerina-unit-test/src/test/resources/test-src/bala/test_projects/test_numeric_literals/Ballerina.toml new file mode 100644 index 000000000000..0be9f738122d --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/bala/test_projects/test_numeric_literals/Ballerina.toml @@ -0,0 +1,4 @@ +[package] +org = "numericliteral" +name = "testproject" +version = "0.1.0" diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/bala/test_projects/test_numeric_literals/main.bal b/tests/jballerina-unit-test/src/test/resources/test-src/bala/test_projects/test_numeric_literals/main.bal new file mode 100644 index 000000000000..0a56ffc48442 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/bala/test_projects/test_numeric_literals/main.bal @@ -0,0 +1,21 @@ +// Copyright (c) 2023 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +// +// WSO2 Inc. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +public type Foo decimal|2f; +public type Foo2 decimal|3d|1|5d|3f|4d|2f|7d|6; +public type Foo3 decimal|5d|3f|4d|2f|7d; +public type Foo4 decimal|5d|4d|7d; +public type Foo5 decimal|4d|2f|3.0|2.1|1; diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/expressions/literals/numeric_literal_assignment.bal b/tests/jballerina-unit-test/src/test/resources/test-src/expressions/literals/numeric_literal_assignment.bal index 0c3496e5457a..e5a1b254463a 100644 --- a/tests/jballerina-unit-test/src/test/resources/test-src/expressions/literals/numeric_literal_assignment.bal +++ b/tests/jballerina-unit-test/src/test/resources/test-src/expressions/literals/numeric_literal_assignment.bal @@ -123,8 +123,8 @@ function testFloatLiteralAsDecimalInUnion() returns boolean { } function testFloatLiteralAsDecimalInUnion_2() returns boolean { - Bar|decimal y = 123.0; - decimal dec = 123.0; + int|decimal y = 12.0; + decimal dec = 12.0; return y is decimal && dec == y; } diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/expressions/literals/numeric_literal_assignment_negative.bal b/tests/jballerina-unit-test/src/test/resources/test-src/expressions/literals/numeric_literal_assignment_negative.bal new file mode 100644 index 000000000000..dc9267c7fb71 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/expressions/literals/numeric_literal_assignment_negative.bal @@ -0,0 +1,414 @@ +// Copyright (c) 2023 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +// +// WSO2 Inc. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +type Foo decimal|2f; +type Foo2 decimal|3d|1|5d|3f|4d|2f|7d|6; +type Foo3 decimal|5d|3f|4d|2f|7d; +type Foo4 decimal|5d|4d|7d; +type Foo5 decimal|4d|2f|3.0|2.1|1; + +function testNumericLiteralAssignmentNegative() { + Foo _ = 3; //error: incompatible types: expected 'Foo', found 'float' + Foo _ = 2; + Foo _ = 2.0; + Foo _ = 1.0; //error: incompatible types: expected 'Foo', found 'float' + Foo _ = 1.2; //error: incompatible types: expected 'Foo', found 'float' + Foo _ = 2f; + Foo _ = 3f; //error: incompatible types: expected 'Foo', found 'float' + Foo _ = 2d; + Foo _ = 3d; + Foo2 _ = 1; + Foo2 _ = 2; // error: incompatible types: expected 'Foo2', found 'int' + Foo2 _ = 3; // error: incompatible types: expected 'Foo2', found 'int' + Foo2 _ = 4; // error: incompatible types: expected 'Foo2', found 'int' + Foo2 _ = 5; // error: incompatible types: expected 'Foo2', found 'int' + Foo2 _ = 6; + Foo2 _ = 7; // error: incompatible types: expected 'Foo2', found 'int' + Foo2 _ = 7.1; // error: incompatible types: expected 'Foo2', found 'float' + Foo3 _ = 2; + Foo3 _ = 3; + Foo3 _ = 4; // error: incompatible types: expected 'Foo3', found 'float' + Foo3 _ = 5; // error: incompatible types: expected 'Foo3', found 'float' + Foo3 _ = 7; // error: incompatible types: expected 'Foo3', found 'float' + Foo3 _ = 7.1; // error: incompatible types: expected 'Foo3', found 'float' + Foo4 _ = 1; + Foo4 _ = 2; + Foo4 _ = 3; + Foo4 _ = 4; + Foo4 _ = 5; + Foo4 _ = 7; + Foo4 _ = 7.1; + Foo5 _ = 4; //error: incompatible types: expected 'Foo5', found 'int' + Foo5 _ = 4.0; //error: incompatible types: expected 'Foo5', found 'float' + Foo5 _ = 5.0; //error: incompatible types: expected 'Foo5', found 'float' + Foo5 _ = 5.2; //error: incompatible types: expected 'Foo5', found 'float' + Foo5 _ = 4f; //error: incompatible types: expected 'Foo5', found 'float' + Foo5 _ = 4d; + Foo5 _ = 5f; //error: incompatible types: expected 'Foo5', found 'float' + Foo5 _ = 5d; + Foo5 _ = 2.0; + Foo5 _ = 2; //error: incompatible types: expected 'Foo5', found 'int' + Foo5 _ = 6.0; //error: incompatible types: expected 'Foo5', found 'float' + Foo5 _ = 6.2; //error: incompatible types: expected 'Foo5', found 'float' + Foo5 _ = 2f; + Foo5 _ = 2d; + Foo5 _ = 6f; //error: incompatible types: expected 'Foo5', found 'float' + Foo5 _ = 6d; + Foo5 _ = 3.0; + Foo5 _ = 3; //error: incompatible types: expected 'Foo5', found 'int' + Foo5 _ = 7.0; //error: incompatible types: expected 'Foo5', found 'float' + Foo5 _ = 7.2; //error: incompatible types: expected 'Foo5', found 'float' + Foo5 _ = 3f; + Foo5 _ = 3d; + Foo5 _ = 7f; //error: incompatible types: expected 'Foo5', found 'float' + Foo5 _ = 7d; + Foo5 _ = 1; + Foo5 _ = 10; //error: incompatible types: expected 'Foo5', found 'int' + Foo5 _ = 1.0; //error: incompatible types: expected 'Foo5', found 'float' + Foo5 _ = 1.2; //error: incompatible types: expected 'Foo5', found 'float' + Foo5 _ = 1f; //error: incompatible types: expected 'Foo5', found 'float' + Foo5 _ = 1d; + Foo5 _ = 10f; //error: incompatible types: expected 'Foo5', found 'float' + Foo5 _ = 10d; + Foo5 _ = 2.1; + Foo5 _ = 2.1f; + Foo5 _ = 2.1d; + Foo5 _ = 8.0; //error: incompatible types: expected 'Foo5', found 'float' + Foo5 _ = 8.2; //error: incompatible types: expected 'Foo5', found 'float' + Foo5 _ = 8d; + Foo5 _ = 8f; //error: incompatible types: expected 'Foo5', found 'float' + Foo5 _ = 9.0; //error: incompatible types: expected 'Foo5', found 'float' + Foo5 _ = 9.2; //error: incompatible types: expected 'Foo5', found 'float' + Foo5 _ = 9d; + Foo5 _ = 9f; //error: incompatible types: expected 'Foo5', found 'float' + Foo5 _ = 24; //error: incompatible types: expected 'Foo5', found 'int' +} + +function testNumericLiteralAssignmentNegative2() { + decimal|4d _ = 8.0; + decimal|4d _ = 8.2; + decimal|4d _ = 8d; + decimal|4d _ = 8f; //error: incompatible types: expected 'decimal|4d', found 'float' + decimal|4d _ = 4; + decimal|4d _ = 4.0; + decimal|4d _ = 5.0; + decimal|4d _ = 5.2; + decimal|4d _ = 4f; //error: incompatible types: expected 'decimal|4d', found 'float' + decimal|4d _ = 4d; + decimal|4d _ = 5f; //error: incompatible types: expected 'decimal|4d', found 'float' + decimal|4d _ = 5d; + decimal|float _ = 8.0; + decimal|float _ = 8.2; + decimal|float _ = 8d; + decimal|float _ = 8f; + decimal|float _ = 9.0; + decimal|float _ = 9.2; + decimal|float _ = 9d; + decimal|float _ = 9f; + decimal|2f _ = 8.0; //error: incompatible types: expected 'decimal|2f', found 'float' + decimal|2f _ = 8.2; //error: incompatible types: expected 'decimal|2f', found 'float' + decimal|2f _ = 8d; + decimal|2f _ = 8f; //error: incompatible types: expected 'decimal|2f', found 'float' + decimal|2f _ = 2.0; + decimal|2f _ = 2; + decimal|2f _ = 6.0; //error: incompatible types: expected 'decimal|2f', found 'float' + decimal|2f _ = 6.2; //error: incompatible types: expected 'decimal|2f', found 'float' + decimal|2f _ = 2f; + decimal|2f _ = 2d; + decimal|2f _ = 6f; //error: incompatible types: expected 'decimal|2f', found 'float' + decimal|2f _ = 6d; + decimal|3.0 _ = 8.0; //error: incompatible types: expected 'decimal|3.0', found 'float' + decimal|3.0 _ = 8.2; //error: incompatible types: expected 'decimal|3.0', found 'float' + decimal|3.0 _ = 8d; + decimal|3.0 _ = 8f; //error: incompatible types: expected 'decimal|3.0', found 'float' + decimal|3.0 _ = 3.0; + decimal|3.0 _ = 3; + decimal|3.0 _ = 7.0; //error: incompatible types: expected 'decimal|3.0', found 'float' + decimal|3.0 _ = 7.2; //error: incompatible types: expected 'decimal|3.0', found 'float' + decimal|3.0 _ = 3f; + decimal|3.0 _ = 3d; + decimal|3.0 _ = 7f; //error: incompatible types: expected 'decimal|3.0', found 'float' + decimal|3.0 _ = 7d; + decimal|1 _ = 8.0; + decimal|1 _ = 8.2; + decimal|1 _ = 8d; + decimal|1 _ = 8f; //error: incompatible types: expected 'decimal|1', found 'float' + decimal|1 _ = 1; + decimal|1 _ = 10; //error: incompatible types: expected 'decimal|1', found 'int' + decimal|1 _ = 1.0; + decimal|1 _ = 1.2; + decimal|1 _ = 1f; //error: incompatible types: expected 'decimal|1', found 'float' + decimal|1 _ = 1d; + decimal|1 _ = 10f; //error: incompatible types: expected 'decimal|1', found 'float' + decimal|1 _ = 10d; + decimal|byte _ = 8.0; + decimal|byte _ = 8.2; + decimal|byte _ = 8d; + decimal|byte _ = 8f; //error: incompatible types: expected 'decimal|byte', found 'float' + decimal|byte _ = 24; + decimal|2.1 _ = 8.0; //error: incompatible types: expected 'decimal|2.1', found 'float' + decimal|2.1 _ = 8.2; //error: incompatible types: expected 'decimal|2.1', found 'float' + decimal|2.1 _ = 8d; + decimal|2.1 _ = 8f; //error: incompatible types: expected 'decimal|2.1', found 'float' + decimal|2.1 _ = 2.1; + decimal|2.1 _ = 2.1f; + decimal|2.1 _ = 2.1d; + 4d|float _ = 4; + 4d|float _ = 4.0; + 4d|float _ = 5.0; + 4d|float _ = 5.2; + 4d|float _ = 4f; + 4d|float _ = 4d; + 4d|float _ = 5f; + 4d|float _ = 5d; //error: incompatible types: expected '4d|float', found 'decimal' + 4d|float _ = 9.0; + 4d|float _ = 9.2; + 4d|float _ = 9d; //error: incompatible types: expected '4d|float', found 'decimal' + 4d|float _ = 9f; + 4d|float _ = 5; + 4d|2f _ = 4; //error: incompatible types: expected '4d|2f', found 'float' + 4d|2f _ = 4.0; //error: incompatible types: expected '4d|2f', found 'float' + 4d|2f _ = 5.0; //error: incompatible types: expected '4d|2f', found 'float' + 4d|2f _ = 5.2; //error: incompatible types: expected '4d|2f', found 'float' + 4d|2f _ = 4f; //error: incompatible types: expected '4d|2f', found 'float' + 4d|2f _ = 4d; + 4d|2f _ = 5f; //error: incompatible types: expected '4d|2f', found 'float' + 4d|2f _ = 5d; //error: incompatible types: expected '4d|2f', found 'decimal' + 4d|2f _ = 2.0; + 4d|2f _ = 2; + 4d|2f _ = 6.0; //error: incompatible types: expected '4d|2f', found 'float' + 4d|2f _ = 6.2; //error: incompatible types: expected '4d|2f', found 'float' + 4d|2f _ = 2f; + 4d|2f _ = 2d; //error: incompatible types: expected '4d|2f', found 'decimal' + 4d|2f _ = 6f; //error: incompatible types: expected '4d|2f', found 'float' + 4d|2f _ = 6d; //error: incompatible types: expected '4d|2f', found 'decimal' + 4d|3.0 _ = 4; //error: incompatible types: expected '4d|3.0', found 'float' + 4d|3.0 _ = 4.0; //error: incompatible types: expected '4d|3.0', found 'float' + 4d|3.0 _ = 5.0; //error: incompatible types: expected '4d|3.0', found 'float' + 4d|3.0 _ = 5.2; //error: incompatible types: expected '4d|3.0', found 'float' + 4d|3.0 _ = 4f; //error: incompatible types: expected '4d|3.0', found 'float' + 4d|3.0 _ = 4d; + 4d|3.0 _ = 5f; //error: incompatible types: expected '4d|3.0', found 'float' + 4d|3.0 _ = 5d; //error: incompatible types: expected '4d|3.0', found 'decimal' + 4d|3.0 _ = 3.0; + 4d|3.0 _ = 3; + 4d|3.0 _ = 7.0; //error: incompatible types: expected '4d|3.0', found 'float' + 4d|3.0 _ = 7.2; //error: incompatible types: expected '4d|3.0', found 'float' + 4d|3.0 _ = 3f; + 4d|3.0 _ = 3d; //error: incompatible types: expected '4d|3.0', found 'decimal' + 4d|3.0 _ = 7f; //error: incompatible types: expected '4d|3.0', found 'float' + 4d|3.0 _ = 7d; //error: incompatible types: expected '4d|3.0', found 'decimal' + 4d|1 _ = 4; //error: incompatible types: expected '4d|1', found 'int' + 4d|1 _ = 4.0; + 4d|1 _ = 5.0; //error: incompatible types: expected '4d|1', found 'decimal' + 4d|1 _ = 5.2; //error: incompatible types: expected '4d|1', found 'decimal' + 4d|1 _ = 4f; //error: incompatible types: expected '4d|1', found 'float' + 4d|1 _ = 4d; + 4d|1 _ = 5f; //error: incompatible types: expected '4d|1', found 'float' + 4d|1 _ = 5d; //error: incompatible types: expected '4d|1', found 'decimal' + 4d|1 _ = 1; + 4d|1 _ = 10; //error: incompatible types: expected '4d|1', found 'int' + 4d|1 _ = 1.0; //error: incompatible types: expected '4d|1', found 'decimal' + 4d|1 _ = 1.2; //error: incompatible types: expected '4d|1', found 'decimal' + 4d|1 _ = 1f; //error: incompatible types: expected '4d|1', found 'float' + 4d|1 _ = 1d; //error: incompatible types: expected '4d|1', found 'decimal' + 4d|1 _ = 10f; //error: incompatible types: expected '4d|1', found 'float' + 4d|1 _ = 10d; //error: incompatible types: expected '4d|1', found 'decimal' + 4d|byte _ = 4; + 4d|byte _ = 5; + 4d|byte _ = 4.0; + 4d|byte _ = 5.0; //error: incompatible types: expected '4d|byte', found 'decimal' + 4d|byte _ = 5.2; //error: incompatible types: expected '4d|byte', found 'decimal' + 4d|byte _ = 4f; //error: incompatible types: expected '4d|byte', found 'float' + 4d|byte _ = 4d; + 4d|byte _ = 5f; //error: incompatible types: expected '4d|byte', found 'float' + 4d|byte _ = 5d; //error: incompatible types: expected '4d|byte', found 'decimal' + 4d|byte _ = 24; + 4d|2.1 _ = 4; //error: incompatible types: expected '4d|2.1', found 'float' + 4d|2.1 _ = 4.0; //error: incompatible types: expected '4d|2.1', found 'float' + 4d|2.1 _ = 5.0; //error: incompatible types: expected '4d|2.1', found 'float' + 4d|2.1 _ = 5.2; //error: incompatible types: expected '4d|2.1', found 'float' + 4d|2.1 _ = 4f; //error: incompatible types: expected '4d|2.1', found 'float' + 4d|2.1 _ = 4d; + 4d|2.1 _ = 5f; //error: incompatible types: expected '4d|2.1', found 'float' + 4d|2.1 _ = 5d; //error: incompatible types: expected '4d|2.1', found 'decimal' + 4d|2.1 _ = 2.1; + 4d|2.1 _ = 2.1f; + 4d|2.1 _ = 2.1d; //error: incompatible types: expected '4d|2.1', found 'decimal' + float|2f _ = 9.0; + float|2f _ = 9.2; + float|2f _ = 9d; //error: incompatible types: expected 'float|2f', found 'decimal' + float|2f _ = 9f; + float|2f _ = 2.0; + float|2f _ = 2; + float|2f _ = 6.0; + float|2f _ = 6.2; + float|2f _ = 2f; + float|2f _ = 2d; //error: incompatible types: expected 'float|2f', found 'decimal' + float|2f _ = 6f; + float|2f _ = 6d; //error: incompatible types: expected 'float|2f', found 'decimal' + float|3.0 _ = 9.0; + float|3.0 _ = 9.2; + float|3.0 _ = 9d; //error: incompatible types: expected 'float|3.0', found 'decimal' + float|3.0 _ = 9f; + float|3.0 _ = 3.0; + float|3.0 _ = 3; + float|3.0 _ = 7.0; + float|3.0 _ = 7.2; + float|3.0 _ = 3f; + float|3.0 _ = 3d; //error: incompatible types: expected 'float|3.0', found 'decimal' + float|3.0 _ = 7f; + float|3.0 _ = 7d; //error: incompatible types: expected 'float|3.0', found 'decimal' + float|1 _ = 9.0; + float|1 _ = 9.2; + float|1 _ = 9d; //error: incompatible types: expected 'float|1', found 'decimal' + float|1 _ = 9f; + float|1 _ = 1; + float|1 _ = 10; //error: incompatible types: expected 'float|1', found 'int' + float|1 _ = 1.0; + float|1 _ = 1.2; + float|1 _ = 1f; + float|1 _ = 1d; //error: incompatible types: expected 'float|1', found 'decimal' + float|1 _ = 10f; + float|1 _ = 10d; //error: incompatible types: expected 'float|1', found 'decimal' + float|byte _ = 9.0; + float|byte _ = 9.2; + float|byte _ = 9d; //error: incompatible types: expected 'float|byte', found 'decimal' + float|byte _ = 9f; + float|byte _ = 24; + float|2.1 _ = 9.0; + float|2.1 _ = 9.2; + float|2.1 _ = 9d; //error: incompatible types: expected 'float|2.1', found 'decimal' + float|2.1 _ = 9f; + float|2.1 _ = 2.1; + float|2.1 _ = 2.1f; + float|2.1 _ = 2.1d; //error: incompatible types: expected 'float|2.1', found 'decimal' + 2f|3.0 _ = 2.0; + 2f|3.0 _ = 2; + 2f|3.0 _ = 6.0; //error: incompatible types: expected '2f|3.0', found 'float' + 2f|3.0 _ = 6.2; //error: incompatible types: expected '2f|3.0', found 'float' + 2f|3.0 _ = 2f; + 2f|3.0 _ = 2d; //error: incompatible types: expected '2f|3.0', found 'decimal' + 2f|3.0 _ = 6f; //error: incompatible types: expected '2f|3.0', found 'float' + 2f|3.0 _ = 6d; //error: incompatible types: expected '2f|3.0', found 'decimal' + 2f|3.0 _ = 3.0; + 2f|3.0 _ = 3; + 2f|3.0 _ = 7.0; //error: incompatible types: expected '2f|3.0', found 'float' + 2f|3.0 _ = 7.2; //error: incompatible types: expected '2f|3.0', found 'float' + 2f|3.0 _ = 3f; + 2f|3.0 _ = 3d; //error: incompatible types: expected '2f|3.0', found 'decimal' + 2f|3.0 _ = 7f; //error: incompatible types: expected '2f|3.0', found 'float' + 2f|3.0 _ = 7d; //error: incompatible types: expected '2f|3.0', found 'decimal' + 2f|1 _ = 2.0; + 2f|1 _ = 2; //error: incompatible types: expected '2f|1', found 'int' + 2f|1 _ = 6.0; //error: incompatible types: expected '2f|1', found 'float' + 2f|1 _ = 6.2; //error: incompatible types: expected '2f|1', found 'float' + 2f|1 _ = 2f; + 2f|1 _ = 2d; //error: incompatible types: expected '2f|1', found 'decimal' + 2f|1 _ = 6f; //error: incompatible types: expected '2f|1', found 'float' + 2f|1 _ = 6d; //error: incompatible types: expected '2f|1', found 'decimal' + 2f|1 _ = 1; + 2f|1 _ = 10; //error: incompatible types: expected '2f|1', found 'int' + 2f|1 _ = 1.0; //error: incompatible types: expected '2f|1', found 'float' + 2f|1 _ = 1.2; //error: incompatible types: expected '2f|1', found 'float' + 2f|1 _ = 1f; //error: incompatible types: expected '2f|1', found 'float' + 2f|1 _ = 1d; //error: incompatible types: expected '2f|1', found 'decimal' + 2f|1 _ = 10f; //error: incompatible types: expected '2f|1', found 'float' + 2f|1 _ = 10d; //error: incompatible types: expected '2f|1', found 'decimal' + 2f|byte _ = 2.0; + 2f|byte _ = 3; + 2f|byte _ = 6.0; //error: incompatible types: expected '2f|byte', found 'float' + 2f|byte _ = 6.2; //error: incompatible types: expected '2f|byte', found 'float' + 2f|byte _ = 2f; + 2f|byte _ = 2d; //error: incompatible types: expected '2f|byte', found 'decimal' + 2f|byte _ = 6f; //error: incompatible types: expected '2f|byte', found 'float' + 2f|byte _ = 6d; //error: incompatible types: expected '2f|byte', found 'decimal' + 2f|byte _ = 24; + 2f|2.1 _ = 2.0; + 2f|2.1 _ = 2; + 2f|2.1 _ = 6.0; //error: incompatible types: expected '2f|2.1', found 'float' + 2f|2.1 _ = 6.2; //error: incompatible types: expected '2f|2.1', found 'float' + 2f|2.1 _ = 2f; + 2f|2.1 _ = 2d; //error: incompatible types: expected '2f|2.1', found 'decimal' + 2f|2.1 _ = 6f; //error: incompatible types: expected '2f|2.1', found 'float' + 2f|2.1 _ = 6d; //error: incompatible types: expected '2f|2.1', found 'decimal' + 2f|2.1 _ = 2.1; + 2f|2.1 _ = 2.1f; + 2f|2.1 _ = 2.1d; //error: incompatible types: expected '2f|2.1', found 'decimal' + 3.0|1 _ = 3.0; + 3.0|1 _ = 3; //error: incompatible types: expected '3.0|1', found 'int' + 3.0|1 _ = 7.0; //error: incompatible types: expected '3.0|1', found 'float' + 3.0|1 _ = 7.2; //error: incompatible types: expected '3.0|1', found 'float' + 3.0|1 _ = 3f; + 3.0|1 _ = 3d; //error: incompatible types: expected '3.0|1', found 'decimal' + 3.0|1 _ = 7f; //error: incompatible types: expected '3.0|1', found 'float' + 3.0|1 _ = 7d; //error: incompatible types: expected '3.0|1', found 'decimal' + 3.0|1 _ = 1; + 3.0|1 _ = 10; //error: incompatible types: expected '3.0|1', found 'int' + 3.0|1 _ = 1.0; //error: incompatible types: expected '3.0|1', found 'float' + 3.0|1 _ = 1.2; //error: incompatible types: expected '3.0|1', found 'float' + 3.0|1 _ = 1f; //error: incompatible types: expected '3.0|1', found 'float' + 3.0|1 _ = 1d; //error: incompatible types: expected '3.0|1', found 'decimal' + 3.0|1 _ = 10f; //error: incompatible types: expected '3.0|1', found 'float' + 3.0|1 _ = 10d; //error: incompatible types: expected '3.0|1', found 'decimal' + 3.0|byte _ = 3.0; + 3.0|byte _ = 3; + 3.0|byte _ = 7.0; //error: incompatible types: expected '3.0|byte', found 'float' + 3.0|byte _ = 7.2; //error: incompatible types: expected '3.0|byte', found 'float' + 3.0|byte _ = 3f; + 3.0|byte _ = 3d; //error: incompatible types: expected '3.0|byte', found 'decimal' + 3.0|byte _ = 7f; //error: incompatible types: expected '3.0|byte', found 'float' + 3.0|byte _ = 7d; //error: incompatible types: expected '3.0|byte', found 'decimal' + 3.0|byte _ = 24; + 3.0|2.1 _ = 3.0; + 3.0|2.1 _ = 3; + 3.0|2.1 _ = 7.0; //error: incompatible types: expected '3.0|2.1', found 'float' + 3.0|2.1 _ = 7.2; //error: incompatible types: expected '3.0|2.1', found 'float' + 3.0|2.1 _ = 3f; + 3.0|2.1 _ = 3d; //error: incompatible types: expected '3.0|2.1', found 'decimal' + 3.0|2.1 _ = 7f; //error: incompatible types: expected '3.0|2.1', found 'float' + 3.0|2.1 _ = 7d; //error: incompatible types: expected '3.0|2.1', found 'decimal' + 3.0|2.1 _ = 2.1; + 3.0|2.1 _ = 2.1f; + 3.0|2.1 _ = 2.1d; //error: incompatible types: expected '3.0|2.1', found 'decimal' + 3.0|2.1 _ = 10; //error: incompatible types: expected '3.0|2.1', found 'float' + 1|byte _ = 1; + 1|byte _ = 10; + 1|byte _ = 1.0; //error: incompatible types: expected '1|byte', found 'float' + 1|byte _ = 1.2; //error: incompatible types: expected '1|byte', found 'float' + 1|byte _ = 1f; //error: incompatible types: expected '1|byte', found 'float' + 1|byte _ = 1d; //error: incompatible types: expected '1|byte', found 'decimal' + 1|byte _ = 10f; //error: incompatible types: expected '1|byte', found 'float' + 1|byte _ = 10d; //error: incompatible types: expected '1|byte', found 'decimal' + 1|byte _ = 24; + 1|2.1 _ = 1; + 1|2.1 _ = 10; //error: incompatible types: expected '1|2.1', found 'int' + 1|2.1 _ = 1.0; //error: incompatible types: expected '1|2.1', found 'float' + 1|2.1 _ = 1.2; //error: incompatible types: expected '1|2.1', found 'float' + 1|2.1 _ = 1f; //error: incompatible types: expected '1|2.1', found 'float' + 1|2.1 _ = 1d; //error: incompatible types: expected '1|2.1', found 'decimal' + 1|2.1 _ = 10f; //error: incompatible types: expected '1|2.1', found 'float' + 1|2.1 _ = 10d; //error: incompatible types: expected '1|2.1', found 'decimal' + 1|2.1 _ = 2.1; + 1|2.1 _ = 2.1f; + 1|2.1 _ = 2.1d; //error: incompatible types: expected '1|2.1', found 'decimal' + byte|2.1 _ = 24; + byte|2.1 _ = 2.1; + byte|2.1 _ = 2.1f; + byte|2.1 _ = 2.1d; //error: incompatible types: expected 'byte|2.1', found 'decimal' + byte|decimal _ = 1; + byte|int _ = 3; +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/types/constant/constant-type-negative.bal b/tests/jballerina-unit-test/src/test/resources/test-src/types/constant/constant-type-negative.bal index 2e9ce450856f..935cf049281e 100644 --- a/tests/jballerina-unit-test/src/test/resources/test-src/types/constant/constant-type-negative.bal +++ b/tests/jballerina-unit-test/src/test/resources/test-src/types/constant/constant-type-negative.bal @@ -33,8 +33,8 @@ type TYPE6 "a"; function userDefinedTypeTests() { CI6 ci6 = 4; // expected '3', found 'int' CF1 cf1 = 4.0; // expected '3.0f', found 'float' - CD1 cd1 = 4.0; // expected '3.0d', found 'float' - CBT3 cbt3 = 4; // expected '3', found 'int' + CD1 cd1 = 4.0; // expected '3.0d', found 'decimal' + CBT3 cbt3 = 4; // expected '3', found 'int' // Uncomment after fixing #33889 CB2 cb2 = true; // expected 'false', found 'boolean' CS2 cs2 = "4"; // expected '"12"', found 'string'