GLBasic forum

Main forum => Bug Reports => Topic started by: MrTAToad on 2011-May-29

Title: Variable declaration in extended types
Post by: MrTAToad on 2011-May-29
I've found that a program using a floating-point variable in an extended type will still compile even if the variable is access like an integer :

Code (glbasic) Select
TYPE TTest
a=5.7

FUNCTION test%:
DEBUG self.a%+"\n"
ENDFUNCTION
ENDTYPE

LOCAL y AS TTest

y.test()


a is defined as a float, but is accessed like its an integer (and the result is a floating-point value).

Do it in a standard function

Code (glbasic) Select
FUNCTION test%:
LOCAL a=5.7

DEBUG a%+"\n"
ENDFUNCTION


and you get a compiler error (which is correct).
Title: Re: Variable declaration in extended types
Post by: MrTAToad on 2011-May-29
Thanks  =D  Gernot's not going to be happy  :)
Title: Re: Variable declaration in extended types
Post by: Kitty Hello on 2011-May-30
Oh, I'm so happy. Soo happy. ... if I wasn't to implement extended types at all :/

I'll have a close look, though.
Title: Re: Variable declaration in extended types
Post by: Moru on 2011-May-30
Well you did say you would regret it, didn't you? :-)
Title: Re: Variable declaration in extended types
Post by: MrTAToad on 2011-May-30
He did too :)
Title: Re: Variable declaration in extended types
Post by: bigsofty on 2011-May-30
If it's any consolation, I initially disliked them but now I really enjoy them now!
Title: Re: Variable declaration in extended types
Post by: Moebius on 2011-Jun-02
Not an extended types problem.  This compiles even with explicit decls. :
Code (glbasic) Select
FOR i = 1 TO 10; NEXT;
I think variables in FOR/NEXT loops are defined temporarily.  This doesn't work:
Code (glbasic) Select
FOR i = 1 TO 10; NEXT;
PRINT i, 10, 10
Title: Re: Variable declaration in extended types
Post by: MrTAToad on 2011-Jun-02
Yes, I forgot about that - I'll delete my previous post  :whistle:

Silly me...