SpiderBasic 3.20 does not enforce AddElement() for structured list assignment, unlike PureBasic

Found an issue in SpiderBasic ? Please report it here !
Webarion
Posts: 15
Joined: Mon Mar 04, 2024 10:47 pm

SpiderBasic 3.20 does not enforce AddElement() for structured list assignment, unlike PureBasic

Post by Webarion »

Hello, I found a discrepancy between the PureBasic and SpiderBasic compilers regarding structured dynamic lists. In PureBasic, the following code throws a compiler error because the list element must be explicitly initialized with AddElement() before assignment. However, SpiderBasic compiles it successfully without any warnings, which breaks the "write once, compile anywhere" syntax rule between PB and SB. Reproduce

Code: Select all

Structure MyMap
  List MyList.i()
EndStructure

Define NewMap MyMap.MyMap()

; This line compiles fine in SB, but causes a compiler error in PB:
MyMap("1")\MyList() = 1
Expected behavior: SpiderBasic should throw a compiler error stating that AddElement() is required, or that direct assignment to a structured list is not allowed, matching PureBasic's strict type safety. Best regards.
Fred
Site Admin
Posts: 1901
Joined: Mon Feb 24, 2014 10:51 am

Re: SpiderBasic 3.20 does not enforce AddElement() for structured list assignment, unlike PureBasic

Post by Fred »

It's a runtime debugger error, right ?
Webarion
Posts: 15
Joined: Mon Mar 04, 2024 10:47 pm

Re: SpiderBasic 3.20 does not enforce AddElement() for structured list assignment, unlike PureBasic

Post by Webarion »

Fred wrote: Thu Sep 17, 2026 9:20 am It's a runtime debugger error, right ?
Yes, this happens at runtime.

Code: Select all

Structure MyMap
List MyList.i()
EndStructure

Define NewMap MyMap.MyMap()

MyMap("1")\MyList() = 1

MessageRequester("","msg")
If this code is compiled to an exe in PureBasic, it compiles successfully, but it will never reach the "msg" output. In SpiderBasic, MessageRequester("msg") works successfully.
It's clear that this is JavaScript, however such behavior can lead to confusion when writing code. That's why I didn't understand why it happens this way.
Another example of the different behavior:

Code: Select all

Define NewList MyList()
Debug ListIndex( MyList() )
; In PureBasic the result is: -1
; In SpiderBasic the result is: 0
Post Reply