E07944: 'sanitized' cannot be used on an extern parameter - the compiler does not generate an extern body, so nothing would clean it; the external implementation must clean its input itself
What went wrong
The 'sanitized' keyword CANNOT be used on a parameter of an extern declaration ('defines extern module'). A method or function cleans its own 'sanitized' parameters on entry, but the compiler does not generate an extern body - so nothing would clean the parameter, and the signature would promise cleaning that never happens.
Worked examples
Compilable examples demonstrating this error and the correct fix:
- ek9 -q 1400 (Can an extern function or method declare a sanitized par...)
Rationale
'sanitized' is a promise to every caller: "pass me untrusted input and it will be cleaned before I use it". The compiler keeps that promise by generating the cleaning at the start of the receiving body. An extern declaration only describes a body that is implemented elsewhere (for example in Java), so the compiler has nowhere to put the cleaning.
The external implementation knows at development time which inputs need cleaning, and cleans them itself - in Java, by calling InputSanitizer.
How to fix it
- REMOVE: 'sanitized' from the extern parameter
- CLEAN: the input inside the external implementation, or
- WRAP: the extern call in an EK9 function whose parameter is 'sanitized'
The [EXAMPLE] section below shows 'sanitized' on an extern method and function, the extern function with a plain parameter, and an ordinary EK9 function that wraps the extern call and takes its parameter as 'sanitized' (its body is generated, so it cleans there).
See also
- E07910: sanitized on wrong type (must be String)
- E07920: sanitized in wrong location (must be incoming parameter)
- E07940: sanitized dropped in an override
- E07944: sanitized on an extern parameter (this error)
https://ek9.io/sanitized.html https://ek9.io/forAI.json#$.sanitizedTypes
Examples
Every example is compiled by the EK9 compiler: the first fails exactly as captioned, the others fix it.
Fails with E07944: 'sanitized' cannot be used on an extern parameter - the compiler does not generate an extern body, so nothing would clean it; the external implementation must clean its input itself
#!ek9 defines extern module error.e07944.bad defines class ExternalStore ExternalStore() //ERROR: an extern method cannot promise to clean its parameter lookup() -> key as String <- rtn as String? store() -> input as sanitized String <- rtn as String? //OK: a plain String parameter on an extern method defines function //ERROR: an extern function cannot promise to clean its parameter externalClean() -> input as sanitized String <- rtn as String? //OK: a plain String parameter on an extern function externalEcho() -> input as String <- rtn as String?
Fixed: Clean in the external implementation
#!ek9 defines extern module error.e07944.good defines function //A plain parameter: the external implementation cleans its own input externalClean() -> input as String <- rtn as String?
Fixed: Or wrap the call in a function with a sanitized parameter
#!ek9 defines module error.e07944.good.wrapper references error.e07944.good::externalClean defines function //Or wrap the call: the compiler writes this body, so it cleans its parameter on entry cleanThenStore() -> input as sanitized String <- rtn as String: externalClean(input)
Questions and answers
These Q&A entries show E07944 and its fix: