Type of union field = [union] with some usage of TYPEOF ?

New to FreeBASIC? Post your questions here.
Post Reply
Tourist Trap
Posts: 2958
Joined: Jun 02, 2015 16:24

Type of union field = [union] with some usage of TYPEOF ?

Post by Tourist Trap »

Hi,
Maybe a silly question, but I find that:

Code: Select all

union UNO
   as OBJECT o
end union

#print typeOf(UNO.o)  ''prints UNO, rather than OBJECT
So as said in the commented part, I would be expecting to be returned the object type (of o) rather that the parent type. Is there a reason for this that I obviously miss?
badidea
Posts: 2591
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Type of union field = [union] with some usage of TYPEOF ?

Post by badidea »

That code gives two errors here as welll:
test.bas(2) error 163: Fields with constructors cannot be part of UNION's or nested TYPE's in 'as OBJECT o'
test.bas(5) error 7: Expected ')', found '.' in '#print typeOf(UNO.o) ''prints UNO, rather than OBJECT'
fxm
Moderator
Posts: 12107
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Type of union field = [union] with some usage of TYPEOF ?

Post by fxm »

Tourist Trap wrote:So as said in the commented part, I would be expecting to be returned the object type (of o) rather that the parent type. Is there a reason for this that I obviously miss?
Your remark match with a known feature request:
#293 Allow using of Sizeof()/​Typeof() on non-static members through type/​union name

- This is now applied in the current fbc version 1.08.
changelog.txt:
Version 1.08.0

.....

[added]
.....
- sf.net feature request #293: allow len/sizeof/typeof for UDT members without expression
.....
- Compiling your code with the current fbc 1.08 now provides:
Compiler output:
C:\Users\.....\FBIde0.4.6r4_fbc1.08.0\FBIDETEMP.bas(2) error 163: Fields with constructors cannot be part of UNION's or nested TYPE's in 'as OBJECT o'
OBJECT
- Extract of the TYPEOF documentation page:
.....
TypeOf also supports passing any intrinsic data type, or user-defined type (and its data fields for fbc version >= 1.08), not only variables defined as those types. Also supported are expressions, the type is inferred from the expression (much like Var).

.....
Tourist Trap
Posts: 2958
Joined: Jun 02, 2015 16:24

Re: Type of union field = [union] with some usage of TYPEOF ?

Post by Tourist Trap »

badidea wrote:That code gives two errors here as welll:
test.bas(2) error 163: Fields with constructors cannot be part of UNION's or nested TYPE's in 'as OBJECT o'
test.bas(5) error 7: Expected ')', found '.' in '#print typeOf(UNO.o) ''prints UNO, rather than OBJECT'
Yes, however the same issue holds whatever the type behavior regarding the constructor, for an Integer for instance.
fxm wrote:
Compiler output:
C:\Users\.....\FBIde0.4.6r4_fbc1.08.0\FBIDETEMP.bas(2) error 163: Fields with constructors cannot be part of UNION's or nested TYPE's in 'as OBJECT o'
OBJECT
- Extract of the TYPEOF documentation page:
.....
TypeOf also supports passing any intrinsic data type, or user-defined type (and its data fields for fbc version >= 1.08), not only variables defined as those types. Also supported are expressions, the type is inferred from the expression (much like Var).

.....
Thanks a lot fxm,

crystal clear as usual, and good news about the improvements of union.
Post Reply