Skip to content

Commit

Permalink
Fix unnecessary conversion warning from integer to real
Browse files Browse the repository at this point in the history
  • Loading branch information
mx990 authored and oberlehner committed Jul 30, 2024
1 parent 5099db0 commit ee9458f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.fordiac.ide.model.data.AnyBitType;
import org.eclipse.fordiac.ide.model.data.AnyIntType;
import org.eclipse.fordiac.ide.model.data.AnyRealType;
import org.eclipse.fordiac.ide.model.data.AnySignedType;
import org.eclipse.fordiac.ide.model.data.AnyStringType;
import org.eclipse.fordiac.ide.model.data.AnyUnsignedType;
Expand Down Expand Up @@ -475,8 +476,10 @@ && isBetterCastPossible(argumentDataType, expectedReturnDataType)) {
private static boolean isCastSemanticallyRelevant(final DataType argumentDataType, final DataType returnDataType) {
// semantically relevant casts:
// - signed to unsigned
// - integer to real
// - involves bit types
return (argumentDataType instanceof AnySignedType && returnDataType instanceof AnyUnsignedType)
|| (argumentDataType instanceof AnyIntType && returnDataType instanceof AnyRealType)
|| argumentDataType instanceof AnyBitType || returnDataType instanceof AnyBitType;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1607,6 +1607,16 @@ class STFunctionValidatorTest {
END_FUNCTION
'''.parse.assertWarning(STCorePackage.eINSTANCE.STFeatureExpression,
STCoreValidator.UNNECESSARY_LITERAL_CONVERSION, "Unnecessary conversion of literal to USINT")
'''
FUNCTION test
VAR_TEMP
INT_VAR: INT;
INT_VAR2: INT;
REAL_VAR: REAL;
END_VAR
REAL_VAR := INT_TO_REAL(INT_VAR) / INT_VAR2;
END_FUNCTION
'''.parse.assertNoIssues
}

@Test
Expand Down

0 comments on commit ee9458f

Please sign in to comment.