mirror of
https://github.com/irmen/prog8.git
synced 2024-09-10 09:54:32 +00:00
don't give error when returning uword value in subroutine that returns STR
This commit is contained in:
parent
58400f53bc
commit
332ba8ed7e
@ -124,6 +124,8 @@ internal class AstChecker(private val program: Program,
|
|||||||
}
|
}
|
||||||
} else if(valueDt.isIterable && expectedReturnValues[0]==DataType.UWORD) {
|
} else if(valueDt.isIterable && expectedReturnValues[0]==DataType.UWORD) {
|
||||||
// you can return a string or array when an uword (pointer) is returned
|
// 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 {
|
else {
|
||||||
errors.err("type $valueDt of return value doesn't match subroutine's return type ${expectedReturnValues[0]}",returnStmt.value!!.position)
|
errors.err("type $valueDt of return value doesn't match subroutine's return type ${expectedReturnValues[0]}",returnStmt.value!!.position)
|
||||||
|
@ -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
|
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()``
|
in the string where the character is present, if you need that, use the ``string.find()``
|
||||||
library function instead)
|
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::
|
.. hint::
|
||||||
Strings/arrays and uwords (=memory address) can often be interchanged.
|
Strings/arrays and uwords (=memory address) can often be interchanged.
|
||||||
|
@ -611,16 +611,11 @@ containment check: ``in``
|
|||||||
txt.print("cc is one of the values")
|
txt.print("cc is one of the values")
|
||||||
}
|
}
|
||||||
|
|
||||||
str email_address = "?????????"
|
str email_address = "name@test.com"
|
||||||
if '@' in email_address {
|
if '@' in email_address {
|
||||||
txt.print("email address seems ok")
|
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: ``&``
|
address of: ``&``
|
||||||
This is a prefix operator that can be applied to a string or array variable or literal value.
|
This is a prefix operator that can be applied to a string or array variable or literal value.
|
||||||
|
Loading…
Reference in New Issue
Block a user