Skip to content

Commit

Permalink
improve error message for non-numeric when choice values
Browse files Browse the repository at this point in the history
  • Loading branch information
irmen committed Mar 3, 2025
1 parent 9d49589 commit 2b6510d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion compiler/src/prog8/compiler/astprocessing/AstChecker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1663,7 +1663,7 @@ internal class AstChecker(private val program: Program,
val constvalues = whenChoice.values!!.map { it.constValue(program) to it.position }
for((constvalue, pos) in constvalues) {
when {
constvalue == null -> errors.err("choice value must be a constant", pos)
constvalue == null -> errors.err("choice values must be constant numbers", pos)
!constvalue.type.isIntegerOrBool -> errors.err("choice value must be a byte or word", pos)
!(conditionType issimpletype constvalue.type) -> {
if(conditionType.isKnown) {
Expand Down
1 change: 1 addition & 0 deletions docs/source/todo.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ TODO
Future Things and Ideas
^^^^^^^^^^^^^^^^^^^^^^^

- allow integer range as when choice? because 1,2,3,4,5 is already allowed, so perhaps 1 to 5 should be allowed too? However, [1,2,3,4,5] usually is the desugared equivalent of 1 to 5 and choice values can't be arrays.
- const values should always either be of type long or float, this is how they were usually treated in const expression evaluation already anyway
- Kotlin: can we use inline value classes in certain spots?
- add float support to the configurable compiler targets
Expand Down

0 comments on commit 2b6510d

Please sign in to comment.