TypeOf() and array

Post bugreports for the Windows version here
Little John
Addict
Addict
Posts: 4823
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

TypeOf() and array

Post by Little John »

TypeOf() cannot handle a plain array as argument.

Code: Select all

; PB 6.30 beta 5

EnableExplicit

Macro ShowType (_x_)
   CompilerSelect TypeOf(_x_)
      CompilerCase #PB_Ascii
         Debug "Ascii"
      CompilerCase #PB_Byte
         Debug "Byte"
      CompilerCase #PB_Character
         Debug "Character"
      CompilerCase #PB_Double
         Debug "Double"
      CompilerCase #PB_Float
         Debug "Float"
      CompilerCase #PB_Integer
         Debug "Integer"
      CompilerCase #PB_Long
         Debug "Long"
      CompilerCase #PB_Quad
         Debug "Quad"
      CompilerCase #PB_String
         Debug "String"
      CompilerCase #PB_Unicode
         Debug "Unicode"
      CompilerCase #PB_Word
         Debug "Word"
      CompilerDefault   
         Debug "unknown"
   CompilerEndSelect
EndMacro


Dim a.i(5)

; ShowType(a)     ; -> error
; ShowType(a())   ; -> error
; ShowType(a(0))  ; -> error
For more details and the background why I want to use it, please see viewtopic.php?t=88114

Same issue probably with lists and maps.
infratec
Always Here
Always Here
Posts: 7767
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: TypeOf() and array

Post by infratec »

According to the help, it's not a bug:
TypeOf kann verwendet werden, um den Typ einer Variable oder eines Struktur-Feldes herauszufinden.
An array is an array and not a variable. It is not listed as allowed object.
Little John
Addict
Addict
Posts: 4823
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: TypeOf() and array

Post by Little John »

infratec wrote: Mon Jan 05, 2026 12:33 pm An array is an array and not a variable. It is not listed as allowed object.
I think at least a(0) can be considered a variable (integer variable in the above example).
So at least

Code: Select all

ShowType(a(0))
should work IMHO.
infratec
Always Here
Always Here
Posts: 7767
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: TypeOf() and array

Post by infratec »

No, it's an array element.

Look in the help at 'variables' for valid objects.

https://www.purebasic.com/documentation ... ables.html
Little John
Addict
Addict
Posts: 4823
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: TypeOf() and array

Post by Little John »

infratec wrote: Mon Jan 05, 2026 2:31 pm No, it's an array element.
Of course it's an array element. And what is an array element, generally speaking? A variable.

And even if you don't consider this a bug, it should work!
So feel free to consider this a feature request if you prefer, that doesn't matter.
infratec
Always Here
Always Here
Posts: 7767
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: TypeOf() and array

Post by infratec »

Yes, it's a feature request and not only for arrays.

Then you can also request the same for lists and maps.
Little John
Addict
Addict
Posts: 4823
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: TypeOf() and array

Post by Little John »

infratec wrote: Mon Jan 05, 2026 2:48 pm Then you can also request the same for lists and maps.
I did mention lists and maps in the first post of this thread.
Post Reply