Skip to content

Commit 57b4eef

Browse files
committed
parser: Verify that "BASE" is followed by "." for base field access
http://www.freebasic.net/forum/viewtopic.php?p=207268#p207268 (cherry picked from commit b579838)
1 parent dc1aa60 commit 57b4eef

File tree

4 files changed

+39
-12
lines changed

4 files changed

+39
-12
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Version 1.02.1
2020
- C backend: -masm=... will now only be passed to gcc for x86[_64] targets
2121
- Screen didn't return an error code if it failed
2222
- Bad code generated for temporary variable destruction in static variable initialization: temporary strings or UDTs with destructors could be destroyed before even being initialized
23+
- "BASE.field" accesses in expressions (not at the start of a line) allowed any token behind "BASE" instead of the ".", for example "BASE : field", or even EOL.
2324

2425

2526
Version 1.02.0

src/compiler/parser-expr-atom.bas

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,10 @@ private function hBaseMemberAccess _
335335
( _
336336
_
337337
) as ASTNODE ptr
338-
338+
339+
'' BASE
340+
assert( lexGetToken( ) = FB_TK_BASE )
341+
339342
var proc = parser.currproc
340343

341344
'' not inside a method?
@@ -359,25 +362,21 @@ private function hBaseMemberAccess _
359362
return astNewCONSTi( 0 )
360363
end if
361364

362-
'' skip BASE
365+
'' BASE
363366
lexSkipToken( LEXCHECK_NOPERIOD )
364367

365-
'' skip '.'
366-
lexSkipToken()
367-
368-
'' (BASE '.')?
369-
if( lexGetToken() <> FB_TK_BASE ) then
370-
exit do
371-
end if
372-
373368
'' '.'
374-
if( lexGetLookAhead( 1 ) <> CHAR_DOT ) then
369+
if( hMatch( CHAR_DOT ) = FALSE ) then
375370
errReport( FB_ERRMSG_EXPECTEDPERIOD )
376-
'' error recovery: skip stmt, return
377371
hSkipStmt( )
378372
return astNewCONSTi( 0 )
379373
end if
380374

375+
'' (BASE '.')?
376+
if( lexGetToken() <> FB_TK_BASE ) then
377+
exit do
378+
end if
379+
381380
base_ = symbGetSubtype( base_ )->udt.base
382381
loop
383382

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
' TEST_MODE : COMPILE_ONLY_FAIL
2+
3+
type A extends object
4+
i1 as integer
5+
end type
6+
7+
type B extends A
8+
declare sub f()
9+
end type
10+
11+
sub B.f()
12+
print base : i1
13+
end sub
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
' TEST_MODE : COMPILE_ONLY_FAIL
2+
3+
type A extends object
4+
i1 as integer
5+
end type
6+
7+
type B extends A
8+
declare sub f()
9+
end type
10+
11+
sub B.f()
12+
print base
13+
i1
14+
end sub

0 commit comments

Comments
 (0)