mirror of
https://github.com/irmen/prog8.git
synced 2025-02-27 03:29:22 +00:00
compiler error for duplicate when choice labels
This commit is contained in:
parent
00d735249b
commit
5540482888
@ -1141,12 +1141,18 @@ internal class AstChecker(private val program: Program,
|
||||
val conditionType = whenStatement.condition.inferType(program).typeOrElse(DataType.STRUCT)
|
||||
if(conditionType !in IntegerDatatypes)
|
||||
errors.err("when condition must be an integer value", whenStatement.position)
|
||||
val choiceValues = whenStatement.choiceValues(program)
|
||||
val occurringValues = choiceValues.map {it.first}
|
||||
val tally = choiceValues.associate { it.second to occurringValues.count { ov->it.first==ov} }
|
||||
tally.filter { it.value>1 }.forEach {
|
||||
errors.err("choice value occurs multiple times", it.key.position)
|
||||
val tally = mutableSetOf<Int>()
|
||||
for((choices, choiceNode) in whenStatement.choiceValues(program)) {
|
||||
if(choices!=null) {
|
||||
for (c in choices) {
|
||||
if(c in tally)
|
||||
errors.err("choice value already occurs earlier", choiceNode.position)
|
||||
else
|
||||
tally.add(c)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(whenStatement.choices.isEmpty())
|
||||
errors.err("empty when statement", whenStatement.position)
|
||||
|
||||
|
@ -2,8 +2,6 @@
|
||||
TODO
|
||||
====
|
||||
|
||||
- compiler error for double when labels
|
||||
|
||||
- add sound to the cx16 tehtriz
|
||||
|
||||
- add const arrays and cost strings
|
||||
|
@ -6,14 +6,19 @@ main {
|
||||
|
||||
; $1F9C0 - $1F9FF PSG registers
|
||||
|
||||
sub init(uword addr, ubyte length) {
|
||||
@(addr+length) = $ea
|
||||
}
|
||||
|
||||
sub start() {
|
||||
|
||||
init($4000, 0)
|
||||
txt.print_uwhex(@($4000), true)
|
||||
ubyte xx=33
|
||||
when xx {
|
||||
1 -> {
|
||||
}
|
||||
2 -> {
|
||||
}
|
||||
else -> {
|
||||
}
|
||||
else -> {
|
||||
}
|
||||
}
|
||||
|
||||
; uword freq = 1181
|
||||
; cx16.vpoke(1, $f9c0, lsb(freq))
|
||||
|
Loading…
x
Reference in New Issue
Block a user