ID:2971021
 
BYOND Version:516
Operating System:Windows 11 Pro 64-bit
Web Browser:Firefox 137.0
Applies to:Dream Maker
Status: Deferred

This issue may be low priority or very difficult to fix, and has been put on the back burner for the time being.
Descriptive Problem Summary:

When creating new type from list reference, a runtime error is generated if this is done directly. If you assign the type from list reference, then later call new on the variable, it succeeds.

https://i.imgur.com/gPljkUx.png

Numbered Steps to Reproduce Problem:
Example below.

Code Snippet (if applicable) to Reproduce Problem:
class
var desc = ""
barbarian desc="Warrior"
necromancer desc="Mage"
var classes = list("Barbarian" = /class/barbarian, "Necromancer" = /class/necromancer)


client/verb/fails()
var
selected_class
class/classy
if("Cancel" == (selected_class = input(src) in list("Barbarian","Necromancer","Cancel"))) return
classy = new classes[selected_class] // Runtime
world<<classy.desc

client/verb/passes()
var
selected_class
class/classy
if("Cancel" == (selected_class = input(src) in list("Barbarian","Necromancer","Cancel"))) return
classy = classes[selected_class] //No Runtime
classy = new classy //No Runtime
world<<classy.desc


Expected Results:

Both examples should pass, as classes[selected_class] should point to the same type path in new assignment, as it does when later called.

Actual Results:
runtime error: new() called with an object of type /list instead of the type path itself proc name: fail (/client/verb/fail) usr: Inuyashaisbest (/mob) src: Inuyashaisbest (/client) usr.loc: null call stack: Inuyashaisbest (/client): fail()

Does the problem occur:
Every time? Or how often?
In other games?
In other user accounts?
On other computers?

When does the problem NOT occur?

Did the problem NOT occur in any earlier versions? If so, what was the last version that worked? (Visit http://www.byond.com/download/build to download old versions for testing.)

Workarounds:

Provided.
I could've sworn this was reported already, but maybe it was just discussed in Discord.

The problem is that the non-working version is a syntax error, so it's actually failing you on the compiler end rather than at runtime. The parser binds the new operator more tightly to the var than the list index operator, so it's interpreting this as (classy = new classes)[selected_class]. Since classes is a list and not a type path, there's the reason it fails.
Lummox JR changed status to 'Deferred'

Login to reply.