Nested Types Comments

General FreeBASIC programming questions.
Post Reply
CanMetax
Posts: 16
Joined: Jan 18, 2018 11:40

Nested Types Comments

Post by CanMetax »

FreeBasic 1.10.0

Hello,

Code: Select all

type foo

	type bar
			'Invalid data types, found ???
			foobar as foo
			foobar as foo '' Invalid data types, found ''' <- apostrophe
			'should be an error message? Duplicated definition, foobar 

	end type
private:
		as ubyte nop= -1
end type

fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Nested Types Comments

Post by fxm »

No, the first error is on the first 'foobar as foo':
"error 24: Invalid data types",
because currently, declaring a non-static member variable by referring to an incomplete type ('foo') is not allowed.

Otherwise, this already works for the typed pointers, for the static member variables, for the parameter declarations and the return declarations of member procedures.
CanMetax
Posts: 16
Joined: Jan 18, 2018 11:40

Re: Nested Types Comments

Post by CanMetax »

okay, i understand.
.
.
foobar as foo "Invalid data types" as fxm explained.

foobar as foo Invalid data types, found '
But the apostrophe is recognized as data type here.

And multiple declarations are not recognized either.


long live foo and :D
long live bar :D

ps:
Great new feature.
Great work!
dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Nested Types Comments

Post by dodicat »

A little tester with a static foo and a foo function, since an actual foo is not allowed inside the nested type bar.

Code: Select all

type foo
   as string  z
	type bar
        as long dummy
        static as foo f
        declare function foobar() byref as foo
        declare constructor
        declare constructor(as string)
        declare operator cast() as string
	end type
    
    
private:
		as ubyte nop= -1
end type

 dim as foo foo.bar.f  ' init the static variable

constructor foo.bar
print __function__ + "(empty)"
end constructor

constructor foo.bar(g as string)
print __function__ + "(parameter)"
this.foobar().z=g
end constructor

operator foo.bar.cast() as string
print __function__
return this.foobar.z
end operator

function foo.bar.foobar() byref as foo
    print __function__
    return f
end function

dim as foo.bar x

 x=type("Hello")
 print x
 

 sleep
 
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Nested Types Comments

Post by fxm »

Note:
For the 'foobar()' member function, returning a 'foo' variable by value (instead of by reference) is also allowed.
Same for parameters of a member procedure.
coderJeff
Site Admin
Posts: 4313
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: Nested Types Comments

Post by coderJeff »

CanMetax wrote: Nov 17, 2022 13:30 foobar as foo Invalid data types, found '
But the apostrophe is recognized as data type here.
ya, unfortunately the error reporting is not very good at times. Somewhat due to the simplistic way that fbc handles error checking internally with a couple of common error reporting subroutines. Improvements to error messages could be improved with some work /addition of context specific error reporting.

So, where the error message is reported often depends on how much source code is parsed before an error check is made:

Code: Select all

type foo
    type bar
      member as unknown '' comment
      ''        ^^^^^^^ error check is made here

      '' 'foo' is something that is known
      foobar as foo
      ''            ^ -- error check is made here

      foobar as foo '' comment
      ''            ^ -- error check is made here
    end type
end type
Because of the common error reporting routines used, the compiler often just reports next or upcoming token instead of what was just parsed.

CanMetax wrote: Nov 17, 2022 13:30 And multiple declarations are not recognized either.
? what do you mean, not this:

Code: Select all

type foo
  type bar
    as single x, y, z
  end type
end type
CanMetax
Posts: 16
Joined: Jan 18, 2018 11:40

Re: Nested Types Comments

Post by CanMetax »

Hello,

Code: Select all

type foo
	type bar
		Foo_ as foo
		Foo_ as foo	  ' Duplicated definition not recognized
	private:
			as ubyte nop= -1
	end type

	type foobar
		Bar_ as bar
		Bar_ as bar  ' error 4: Duplicated definition, Bar_
	private:
		as ubyte nop= -1
	end type

private:
 as ubyte nop= -1
end type
die erste double definition wird nicht erkannt.
die zweit wird erkannt.

das meine ich.
coderJeff
Site Admin
Posts: 4313
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: Nested Types Comments

Post by coderJeff »

CanMetax wrote: Nov 19, 2022 10:21 the first double definition is not recognized.
the second is recognized.

I mean that.
In this context it's not a double definition. But it is an error. The "Foo_ as foo" is not allowed at all. A member of nested named type can not be a parent type. In this context 'foo' is an invalid type when used as the data type of a member of a nested named type.

When a statement has more than one error, only the first error is supposed to be shown.
But as can see, depends on comments, and due to fbc parsing inconsistency, user gets different reports:

Code: Select all

'' 2 errors displayed
type T1
	m1 as unknown '' comment 
	m1 as unknown
end type

'' 1 error displayed (2 errors internally, the second is not displayed)
type T2
	m1 as unknown 
	m1 as unknown '' comment
end type
So, with the comments, this actually indicates inconsistency in parsing and error reporting in any types, not only in nested types.
coderJeff
Site Admin
Posts: 4313
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: Nested Types Comments

Post by coderJeff »

moved to general forum
Post Reply