@@ -1794,6 +1794,7 @@ class Negation extends TNegation, Formula {
17941794
17951795/** An expression, such as `x+4`. */
17961796class Expr extends TExpr , AstNode {
1797+ cached
17971798 Type getType ( ) { none ( ) }
17981799}
17991800
@@ -1874,15 +1875,14 @@ class AddSubExpr extends TAddSubExpr, BinOpExpr {
18741875 result = this .getLeftOperand ( ) .getType ( ) and
18751876 result = this .getRightOperand ( ) .getType ( )
18761877 or
1877- // Both operands are subtypes of `int`
1878- result .getName ( ) = "int" and
1879- result = this .getLeftOperand ( ) .getType ( ) .getASuperType * ( ) and
1880- result = this .getRightOperand ( ) .getType ( ) .getASuperType * ( )
1878+ // Both operands are subtypes of `int` / `string` / `float`
1879+ exprOfPrimitiveAddType ( result ) = this .getLeftOperand ( ) and
1880+ exprOfPrimitiveAddType ( result ) = this .getRightOperand ( )
18811881 or
18821882 // Coercion to from `int` to `float`
18831883 exists ( PrimitiveType i | result .getName ( ) = "float" and i .getName ( ) = "int" |
18841884 this .getAnOperand ( ) .getType ( ) = result and
1885- this .getAnOperand ( ) . getType ( ) . getASuperType * ( ) = i
1885+ this .getAnOperand ( ) = exprOfPrimitiveAddType ( i )
18861886 )
18871887 or
18881888 // Coercion to `string`
@@ -1899,6 +1899,18 @@ class AddSubExpr extends TAddSubExpr, BinOpExpr {
18991899 }
19001900}
19011901
1902+ pragma [ noinline]
1903+ private Expr exprOfPrimitiveAddType ( PrimitiveType t ) {
1904+ result .getType ( ) = getASubTypeOfAddPrimitive ( t )
1905+ }
1906+
1907+ private Type getASubTypeOfAddPrimitive ( PrimitiveType prim ) {
1908+ result = prim and
1909+ result .getName ( ) = [ "int" , "string" , "float" ]
1910+ or
1911+ result .getASuperType ( ) = getASubTypeOfAddPrimitive ( prim )
1912+ }
1913+
19021914/**
19031915 * An addition expression, such as `x + y`.
19041916 */
0 commit comments