diff --git a/packages/kbn-esql-validation-autocomplete/src/shared/helpers.ts b/packages/kbn-esql-validation-autocomplete/src/shared/helpers.ts index ce9cec58575fc..e3e3da4277344 100644 --- a/packages/kbn-esql-validation-autocomplete/src/shared/helpers.ts +++ b/packages/kbn-esql-validation-autocomplete/src/shared/helpers.ts @@ -46,7 +46,7 @@ import { } from '../definitions/types'; import type { ESQLRealField, ESQLVariable, ReferenceMaps } from '../validation/types'; import { removeMarkerArgFromArgsList } from './context'; -import { isNumericDecimalType } from './esql_types'; +import { compareTypesWithLiterals, isNumericDecimalType } from './esql_types'; import type { ReasonTypes } from './types'; import { DOUBLE_TICKS_REGEX, EDITOR_MARKER, SINGLE_BACKTICK } from './constants'; import type { EditorContext } from '../autocomplete/types'; @@ -473,7 +473,7 @@ export function checkFunctionArgMatchesDefinition( const lowerArgType = argType?.toLowerCase(); const lowerArgCastType = arg.castType?.toLowerCase(); return ( - lowerArgType === lowerArgCastType || + compareTypesWithLiterals(lowerArgCastType, lowerArgType) || // for valid shorthand casts like 321.12::int or "false"::bool (['int', 'bool'].includes(lowerArgCastType) && argType.startsWith(lowerArgCastType)) ); diff --git a/packages/kbn-esql-validation-autocomplete/src/validation/esql_validation_meta_tests.json b/packages/kbn-esql-validation-autocomplete/src/validation/esql_validation_meta_tests.json index 736159b36384d..a646c0323a76f 100644 --- a/packages/kbn-esql-validation-autocomplete/src/validation/esql_validation_meta_tests.json +++ b/packages/kbn-esql-validation-autocomplete/src/validation/esql_validation_meta_tests.json @@ -9546,6 +9546,11 @@ "error": [], "warning": [] }, + { + "query": "from a_index | where 1::string==\"keyword\"", + "error": [], + "warning": [] + }, { "query": "from a_index | eval trim(\"23\"::double)", "error": [ diff --git a/packages/kbn-esql-validation-autocomplete/src/validation/validation.test.ts b/packages/kbn-esql-validation-autocomplete/src/validation/validation.test.ts index 66de6c7fc70ad..dd04f0e506fe8 100644 --- a/packages/kbn-esql-validation-autocomplete/src/validation/validation.test.ts +++ b/packages/kbn-esql-validation-autocomplete/src/validation/validation.test.ts @@ -1636,6 +1636,8 @@ describe('validation logic', () => { // accepts casting with multiple types testErrorsAndWarnings('from a_index | eval 1::keyword::long::double', []); + testErrorsAndWarnings('from a_index | where 1::string=="keyword"', []); + // takes into account casting in function arguments testErrorsAndWarnings('from a_index | eval trim("23"::double)', [ 'Argument of [trim] must be [keyword], found value ["23"::double] type [double]',