don't give error when returning uword value in subroutine that returns STR

This commit is contained in:
Irmen de Jong 2023-12-14 01:41:23 +01:00
parent 58400f53bc
commit 332ba8ed7e
3 changed files with 10 additions and 6 deletions

View File

@ -124,6 +124,8 @@ internal class AstChecker(private val program: Program,
}
} else if(valueDt.isIterable && expectedReturnValues[0]==DataType.UWORD) {
// you can return a string or array when an uword (pointer) is returned
} else if(valueDt istype DataType.UWORD && expectedReturnValues[0]==DataType.STR) {
// you can return a uword pointer when the return type is a string
}
else {
errors.err("type $valueDt of return value doesn't match subroutine's return type ${expectedReturnValues[0]}",returnStmt.value!!.position)

View File

@ -391,6 +391,13 @@ Using the ``in`` operator you can easily check if a character is present in a st
example: ``if '@' in email_address {....}`` (however this gives no clue about the location
in the string where the character is present, if you need that, use the ``string.find()``
library function instead)
**Caution:**
This checks *all* elements in the string with the length as it was initially declared.
Even when a string was changed and is terminated early with a 0-byte early,
the containment check with ``in`` will still look at all character positions in the initial string.
Consider using ``string.find`` followed by ``if_cs`` (for instance) to do a "safer" search
for a character in such strings (one that stops at the first 0 byte)
.. hint::
Strings/arrays and uwords (=memory address) can often be interchanged.

View File

@ -611,16 +611,11 @@ containment check: ``in``
txt.print("cc is one of the values")
}
str email_address = "?????????"
str email_address = "name@test.com"
if '@' in email_address {
txt.print("email address seems ok")
}
.. caution::
This check compares the needle against *all* elements in the haystack.
For byte arrays and strings(!), this means it considers *all* elements in the array or string with the length as it was declared.
Even when a string was changed and is terminated early with a 0-byte early.
Consider using ``string.find`` followed by ``if_cs`` (for instance) to do a "safer" containment check in such strings.
address of: ``&``
This is a prefix operator that can be applied to a string or array variable or literal value.