ID:1798961
 
(See the best response by Lummox JR.)
Problem description:

Hi, the problem that I am facing is that the DM compiler will not warn if non-constant expressions are used in the branches of a switch statement. Instead it seems that the switch statement fails silently.

Has anyone else encountered this problem?
Examples?
No, in your example you are still using constant expressions in the switch. I mean something like this:

/mob/example
var/temperature

//This is a toy example to get the point across.
/mob/example/proc/process_temperature()
temperature = get_environment()
var/lowlimit = calc_dynamic_lowlimit(src.loc)
var/highlimit = calc_dynamic_highlimit(src.loc)
var/average = (lowlimit + highlimit)/2
switch(temperature)
if(-INFINITY to lowlimit)
src << "below lowlimit"
if(lowlimit to average)
src << "below average"
if(average to highlimit)
src << "above average"
if(highlimit to INFINITY)
src << "above highlimit"
else
src << "something else"


The problem that was reported to me was that in the above case src will always recieve "something else" as all of the switch statement branches fail.

Now before anyone posts any more "code" answers, I want to make this clear because it seems like people aren't getting it.

I am not looking for a code answer. I am not asking for help writing DM code, and that is not the problem.

I am already aware that switch does not work with non-constant expressions. I am familiar with the DM documentation where in chapter 6.19 it says switch works with constant expressions. This is not the issue.

The problem I am facing is that if you do use it with non-constant expressions, DM compiles it without errors and the code fails silently at runtime.

This is a huge problem when you are working with a codebase that has hundreds of source files that have been written by dozens of people over more than five years.

I am looking for a way to get DM to produce an error when you use switch with non-constant expressions. That way when someone who is less familiar with DM does make this mistake, we know about it right away.

If this is the wrong forum please let me know.
Best response
Actually I think this warrants a bug report. I agree that the compiler should produce an error on these cases. I'll take a look if I have a chance, though compiler warnings are low-priority.