{"record":{"id":"3e93f7828b631d7b","repo":"apache/cassandra","slug":"ambiguous-negation-use-type-casts-to-disambiguate","errorCode":null,"errorMessage":"Ambiguous negation: use type casts to disambiguate","messagePattern":"Ambiguous negation: use type casts to disambiguate","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/functions/FunctionResolver.java","lineNumber":185,"sourceCode":"        if (compatibles.size() > 1)\n        {\n            if (OperationFcts.isOperation(name))\n            {\n                if (receiverType != null && !containsMarkers(providedArgs))\n                {\n                    for (Function toTest : compatibles)\n                    {\n                        List<AbstractType<?>> argTypes = toTest.argTypes();\n                        if (receiverType.equals(argTypes.get(0)) && receiverType.equals(argTypes.get(1)))\n                            return toTest;\n                    }\n                }\n                throw invalidRequest(\"Ambiguous '%s' operation with args %s and %s: use type hint to disambiguate, example '(int) ?'\",\n                                     OperationFcts.getOperator(name), providedArgs.get(0), providedArgs.get(1));\n            }\n\n            if (OperationFcts.isNegation(name))\n                throw invalidRequest(\"Ambiguous negation: use type casts to disambiguate\");\n\n            throw invalidRequest(\"Ambiguous call to function %s (can be matched by following signatures: %s): use type casts to disambiguate\",\n                                 name, format(compatibles));\n        }\n\n        return compatibles.get(0);\n    }\n\n    /**\n     * Checks if at least one of the specified arguments is a marker.\n     *\n     * @param args the arguments to check\n     * @return {@code true} if if at least one of the specified arguments is a marker, {@code false} otherwise\n     */\n    private static boolean containsMarkers(List<? extends AssignmentTestable> args)\n    {\n        return args.stream().anyMatch(Marker.Raw.class::isInstance);\n    }","sourceCodeStart":167,"sourceCodeEnd":203,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/functions/FunctionResolver.java#L167-L203","documentation":"Specific to the unary negation operator (-). FunctionResolver found multiple compatible signatures for negating a value (e.g. the operand's type can coerce to both int and float negation overloads) and no type hint exists, so it throws a targeted message instead of the generic ambiguous-call error, instructing the developer to use explicit type casts.","triggerScenarios":"A CQL query like SELECT -some_varint_or_decimal_col FROM t where the operand type is compatible with more than one negation signature and the surrounding context gives no receiver type.","commonSituations":"Negating decimal/varint/float columns where numeric literals or comparisons nearby don't pin a type; users writing -col in a SELECT list with no other typing context.","solutions":["Cast the operand explicitly: SELECT -(int) col FROM t or -(double) col FROM t","Pin the result with CAST: SELECT CAST(-col AS double) FROM t","Use the expression where a typed receiver exists (e.g. compare to a typed literal)"],"exampleFix":"// before\nSELECT -amount FROM orders; // amount is decimal, ambiguous\n// after\ndatastax session.execute(\"SELECT -(double)amount FROM orders\");","handlingStrategy":"validation","validationCode":"function checkNegation(colType) { if (['decimal','varint','float'].includes(colType)) console.warn('negation ambiguous: cast explicitly, e.g. -(double)col'); }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never write bare -col on non-int columns; cast first","Pin expression types with CAST when column types can coerce multiple ways"],"tags":["cql","operators","ambiguity"],"backgroundTag":"invalid-argument","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}