Skip to content

Commit f91f496

Browse files
committed
parser: Disallow static member var in nested UDT (#748)
1 parent 7237a1e commit f91f496

File tree

6 files changed

+27
-2
lines changed

6 files changed

+27
-2
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ Version 1.01.0
6666
- #760: RETURN and FUNCTION= couldn't be used together in byref functions returning an UDT with constructor. This check is now only applied to functions returning byval.
6767
- #755: If no result is set in byref functions, the compiler will now show an error instead of a warning (because a byref function defaults to returning a null reference, most likely causing a crash at runtime)
6868
- Better error message for function result assignments outside of the function (#754), and for illegal use of Exit Sub|Function|...
69+
- #748: Static member variables in UDTs inside procedures or scope blocks were allowed without error message (but didn't and cannot fully work in this situation, like methods). The compiler will now show an error in this case.
6970

7071

7172
Version 1.00.0 (former 0.91.0):

src/compiler/error.bas

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ declare function hMakeParamDesc _
345345
@"VIRTUAL used on non-member procedure", _
346346
@"Invalid initializer", _
347347
@"Objects with default [con|de]structors or methods are only allowed in the module level", _
348+
@"Static member variable in nested UDT (only allowed in toplevel UDTs)", _
348349
@"Symbol not a CLASS, ENUM, TYPE or UNION type", _
349350
@"Too many elements", _
350351
@"Only data members supported", _

src/compiler/error.bi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ enum FB_ERRMSG
266266
FB_ERRMSG_VIRTUALNONMEMBERPROC
267267
FB_ERRMSG_INVALIDINITIALIZER
268268
FB_ERRMSG_NOOOPINFUNCTIONS
269+
FB_ERRMSG_NOSTATICMEMBERVARINNESTEDUDT
269270
FB_ERRMSG_EXPECTEDUDT
270271
FB_ERRMSG_TOOMANYELEMENTS
271272
FB_ERRMSG_NOTADATAMEMBER

src/compiler/parser-decl-struct.bas

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -890,7 +890,7 @@ decl_inner: '' it's an anonymous inner UDT
890890
end if
891891
end sub
892892

893-
private sub hCheckForCDtorOrMethods( byval sym as FBSYMBOL ptr )
893+
private sub hDisallowNestedClasses( byval sym as FBSYMBOL ptr )
894894
dim as FBSYMBOL ptr member = any
895895
'' Not at module level?
896896
if( parser.scope > FB_MAINSCOPE ) then
@@ -899,10 +899,14 @@ private sub hCheckForCDtorOrMethods( byval sym as FBSYMBOL ptr )
899899
'' (Note: assuming symbStructEnd() was already called,
900900
'' thus any implicit members were already added by
901901
'' symbUdtDeclareDefaultMembers())
902+
'' Similar for static member variables (really Externs); normal
903+
'' Externs aren't allowed in scopes either.
902904
member = symbGetCompSymbTb( sym ).head
903905
while( member )
904906
if( symbIsProc( member ) ) then
905907
errReportEx( FB_ERRMSG_NOOOPINFUNCTIONS, symbGetName( member ) )
908+
elseif( symbIsVar( member ) and symbIsExtern( member ) ) then
909+
errReportEx( FB_ERRMSG_NOSTATICMEMBERVARINNESTEDUDT, symbGetName( member ) )
906910
end if
907911
member = member->next
908912
wend
@@ -1031,7 +1035,7 @@ sub cTypeDecl( byval attrib as integer )
10311035
parser.currblock = currblocksym
10321036
parser.scope = scope_depth
10331037

1034-
hCheckForCDtorOrMethods( sym )
1038+
hDisallowNestedClasses( sym )
10351039

10361040
'' end the compound
10371041
stk = cCompStmtGetTOS( FB_TK_TYPE )
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
' TEST_MODE : COMPILE_ONLY_FAIL
2+
3+
sub test( )
4+
type UDT
5+
dummy as integer
6+
7+
static i as integer
8+
end type
9+
end sub
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
' TEST_MODE : COMPILE_ONLY_FAIL
2+
3+
scope
4+
type UDT
5+
dummy as integer
6+
7+
static i as integer
8+
end type
9+
end scope

0 commit comments

Comments
 (0)