@@ -819,7 +819,7 @@ class NewType extends TNewType, TypeDeclaration, ModuleDeclaration {
819819 * A branch in a `newtype`.
820820 * E.g. `Bar()` or `Baz()` in `newtype Foo = Bar() or Baz()`.
821821 */
822- class NewTypeBranch extends TNewTypeBranch , PredicateOrBuiltin , TypeDeclaration {
822+ class NewTypeBranch extends TNewTypeBranch , Predicate , TypeDeclaration {
823823 QL:: DatatypeBranch branch ;
824824
825825 NewTypeBranch ( ) { this = TNewTypeBranch ( branch ) }
@@ -835,7 +835,7 @@ class NewTypeBranch extends TNewTypeBranch, PredicateOrBuiltin, TypeDeclaration
835835 }
836836
837837 /** Gets the body of this branch. */
838- Formula getBody ( ) { toQL ( result ) = branch .getChild ( _) .( QL:: Body ) .getChild ( ) }
838+ override Formula getBody ( ) { toQL ( result ) = branch .getChild ( _) .( QL:: Body ) .getChild ( ) }
839839
840840 override NewTypeBranchType getReturnType ( ) { result .getDeclaration ( ) = this }
841841
@@ -1551,7 +1551,7 @@ class ExprAggregate extends TExprAggregate, Aggregate {
15511551
15521552 override Type getType ( ) {
15531553 exists ( PrimitiveType prim | prim = result |
1554- kind .regexpMatch ( "(strict)?count|sum|min|max|rank " ) and
1554+ kind .regexpMatch ( "(strict)?count" ) and
15551555 result .getName ( ) = "int"
15561556 or
15571557 kind .regexpMatch ( "(strict)?concat" ) and
@@ -1615,16 +1615,16 @@ class FullAggregate extends TFullAggregate, Aggregate {
16151615
16161616 override Type getType ( ) {
16171617 exists ( PrimitiveType prim | prim = result |
1618- kind . regexpMatch ( "(strict)?( count|sum|min|max|rank)" ) and
1618+ kind = [ " count" , "strictcount" ] and
16191619 result .getName ( ) = "int"
16201620 or
16211621 kind .regexpMatch ( "(strict)?concat" ) and
16221622 result .getName ( ) = "string"
16231623 )
16241624 or
1625- kind = [ "any" , "min" , "max" , "unique" ] and
1625+ kind = [ "any" , "min" , "max" , "unique" , "rank" , "sum" , "strictsum" ] and
16261626 not exists ( this .getExpr ( _) ) and
1627- result = this .getArgument ( 0 ) .getTypeExpr ( ) . getResolvedType ( )
1627+ result = this .getArgument ( 0 ) .getType ( )
16281628 or
16291629 not kind = [ "count" , "strictcount" ] and
16301630 result = this .getExpr ( 0 ) .getType ( )
@@ -1761,6 +1761,10 @@ class Super extends TSuper, Expr {
17611761 Super ( ) { this = TSuper ( _) }
17621762
17631763 override string getAPrimaryQlClass ( ) { result = "Super" }
1764+
1765+ override Type getType ( ) {
1766+ exists ( MemberCall call | call .getBase ( ) = this | result = call .getTarget ( ) .getDeclaringType ( ) )
1767+ }
17641768}
17651769
17661770/** An access to `result`. */
@@ -1794,6 +1798,7 @@ class Negation extends TNegation, Formula {
17941798
17951799/** An expression, such as `x+4`. */
17961800class Expr extends TExpr , AstNode {
1801+ cached
17971802 Type getType ( ) { none ( ) }
17981803}
17991804
@@ -1874,15 +1879,14 @@ class AddSubExpr extends TAddSubExpr, BinOpExpr {
18741879 result = this .getLeftOperand ( ) .getType ( ) and
18751880 result = this .getRightOperand ( ) .getType ( )
18761881 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 * ( )
1882+ // Both operands are subtypes of `int` / `string` / `float`
1883+ exprOfPrimitiveAddType ( result ) = this .getLeftOperand ( ) and
1884+ exprOfPrimitiveAddType ( result ) = this .getRightOperand ( )
18811885 or
18821886 // Coercion to from `int` to `float`
18831887 exists ( PrimitiveType i | result .getName ( ) = "float" and i .getName ( ) = "int" |
18841888 this .getAnOperand ( ) .getType ( ) = result and
1885- this .getAnOperand ( ) . getType ( ) . getASuperType * ( ) = i
1889+ this .getAnOperand ( ) = exprOfPrimitiveAddType ( i )
18861890 )
18871891 or
18881892 // Coercion to `string`
@@ -1899,6 +1903,25 @@ class AddSubExpr extends TAddSubExpr, BinOpExpr {
18991903 }
19001904}
19011905
1906+ pragma [ noinline]
1907+ private Expr exprOfPrimitiveAddType ( PrimitiveType t ) {
1908+ result .getType ( ) = getASubTypeOfAddPrimitive ( t )
1909+ }
1910+
1911+ /**
1912+ * Gets a subtype of the given primitive type `prim`.
1913+ * This predicate does not consider float to be a supertype of int.
1914+ */
1915+ private Type getASubTypeOfAddPrimitive ( PrimitiveType prim ) {
1916+ result = prim and
1917+ result .getName ( ) = [ "int" , "string" , "float" ]
1918+ or
1919+ exists ( Type superType | superType = getASubTypeOfAddPrimitive ( prim ) |
1920+ result .getASuperType ( ) = superType and
1921+ not ( result .getName ( ) = "int" and superType .getName ( ) = "float" )
1922+ )
1923+ }
1924+
19021925/**
19031926 * An addition expression, such as `x + y`.
19041927 */
@@ -1939,15 +1962,18 @@ class MulDivModExpr extends TMulDivModExpr, BinOpExpr {
19391962 this .getLeftOperand ( ) .getType ( ) = result and
19401963 this .getRightOperand ( ) .getType ( ) = result
19411964 or
1942- // Both operands are subtypes of `int`
1943- result .getName ( ) = "int" and
1944- result = this .getLeftOperand ( ) . getType ( ) . getASuperType * ( ) and
1945- result = this .getRightOperand ( ) . getType ( ) . getASuperType * ( )
1965+ // Both operands are subtypes of `int`/`float`
1966+ result .getName ( ) = [ "int" , "float" ] and
1967+ exprOfPrimitiveAddType ( result ) = this .getLeftOperand ( ) and
1968+ exprOfPrimitiveAddType ( result ) = this .getRightOperand ( )
19461969 or
19471970 // Coercion from `int` to `float`
19481971 exists ( PrimitiveType i | result .getName ( ) = "float" and i .getName ( ) = "int" |
1949- this .getAnOperand ( ) .getType ( ) = result and
1950- this .getAnOperand ( ) .getType ( ) .getASuperType * ( ) = i
1972+ this .getLeftOperand ( ) = exprOfPrimitiveAddType ( result ) and
1973+ this .getRightOperand ( ) = exprOfPrimitiveAddType ( i )
1974+ or
1975+ this .getRightOperand ( ) = exprOfPrimitiveAddType ( result ) and
1976+ this .getLeftOperand ( ) = exprOfPrimitiveAddType ( i )
19511977 )
19521978 }
19531979
@@ -2281,6 +2307,8 @@ module YAML {
22812307 )
22822308 }
22832309
2310+ YAMLListItem getListItem ( ) { toQL ( result ) .getParent ( ) = yamle }
2311+
22842312 /** Gets the value of this YAML entry. */
22852313 YAMLValue getValue ( ) {
22862314 exists ( QL:: YamlKeyvaluepair pair |
@@ -2393,7 +2421,7 @@ module YAML {
23932421 deps .getLocation ( ) .getFile ( ) = file and entry .getLocation ( ) .getFile ( ) = file
23942422 |
23952423 deps .isRoot ( ) and
2396- deps .getKey ( ) .getQualifiedName ( ) = "dependencies" and
2424+ deps .getKey ( ) .getQualifiedName ( ) = [ "dependencies" , "libraryPathDependencies" ] and
23972425 entry .getLocation ( ) .getStartLine ( ) = 1 + deps .getLocation ( ) .getStartLine ( ) and
23982426 entry .getLocation ( ) .getStartColumn ( ) > deps .getLocation ( ) .getStartColumn ( )
23992427 )
@@ -2408,8 +2436,11 @@ module YAML {
24082436
24092437 predicate hasDependency ( string name , string version ) {
24102438 exists ( YAMLEntry entry | this .isADependency ( entry ) |
2411- entry .getKey ( ) .getQualifiedName ( ) = name and
2439+ entry .getKey ( ) .getQualifiedName ( ) . trim ( ) = name and
24122440 entry .getValue ( ) .getValue ( ) = version
2441+ or
2442+ name = entry .getListItem ( ) .getValue ( ) .getValue ( ) .trim ( ) and
2443+ version = "\"*\""
24132444 )
24142445 }
24152446
@@ -2431,7 +2462,7 @@ module YAML {
24312462 */
24322463 QLPack getADependency ( ) {
24332464 exists ( string name | this .hasDependency ( name , _) |
2434- result .getName ( ) .replaceAll ( "-" , "/" ) = name
2465+ result .getName ( ) .replaceAll ( "-" , "/" ) = name . replaceAll ( "-" , "/" )
24352466 )
24362467 }
24372468
0 commit comments