CommandHelper

CommandHelper

46.5k Downloads

Build 2930+ breaks "smartstring" switch() cases

LadyCailinBot opened this issue ยท 3 comments

commented

CMDHELPER-3109 - Reported by Nessiesson

Compiling

@string = "Foo";
switch(@string) {
	case "Foo":
		noop();
}

throws

[14:40:47 INFO]: COMPILE ERROR: Cases for a switch statement must be constant, not variable
        :D:\Lethe\plugins\CommandHelper\main.ms:3

where line 3 is the one containing the "smartstring" case.

The error goes away if you replace the "smartstring" with a regular string, i.e.,

	case 'Foo':
commented

Comment by PseudoKnight

This exception is because switch() checks to see if cases are dynamic, and smart strings are functions, thus dynamic. So let's say we want to support double quotes in places single quotes work (which the wiki says in the Strings page). We'd probably want to convert a smart_string() to a CString in the compiler if it doesn't find an IVariable. This should be simple.

commented

Comment by PseudoKnight

Just remember, this is non-optimal. Since smart strings do extra work, it's faster to just make it a string.

commented

Comment by PseudoKnight

So I changed it so that if it doesn't detect an @ symbol then it just makes it a regular string. The only thing missing is making escaped @ symbols (eg. "\@") a string too. But this is going to require some extra work; LC thinks we'll probably end up reordering compile time optimizations so that switch(){} doesn't muck up smart_string(). (and consequently fix some other issues too)