Skip to content

Commit 87ecd23

Browse files
committed
fbc: fix bad error recovery of overloaded operator []
For example: type T extends object declare operator []( byval index as integer) as any ptr end type dim as T x x[0].invalid /' fbc 1.09: Aborting due to runtime error 12 ("segmentation violation" signal) fbc 1.10: error 265: Symbol not a CLASS, ENUM, TYPE or UNION type, before 'invalid' in 'x[0].invalid' '/
1 parent 1b8bdf6 commit 87ecd23

File tree

8 files changed

+136
-1
lines changed

8 files changed

+136
-1
lines changed

changelog.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ Version 1.10.0
125125
- fbc: discard assignments and constructor calls in initializers that would write outside of the target when emitting initializer lists - previously, up-casted initializers were writing beyond the limits of the target and trashing memory
126126
- fix regression due to previous change on sf.net #917: optimization of 'm += s'. The optimization failed to consider 's = s + expr' where expr might contain 's'. In such a case, the optimization cannot be applied.
127127
- fbc: basic-macros: improve the handling of optional parens in function like macros by ending a macro argument list on the number of arguments expected (non-variadic macros only).
128-
- fbc: bad error recovery after overloaded operator [] caused compiler crash, for example if overloaded operator [] is found but can't be used due to mixing const and non-const types.
128+
- fbc: bad error recovery after overloaded operator [] caused compiler crash, for example if overloaded operator [] is found but can't be used due to mixing const and non-const types, or invalid members
129129
- fbc: improve error message 215 to indicate that only static members can be accessed from parameter intializers as well as static functions
130130
- fbc: #cmdline "-c ..." needs to restart parser since code generation is affected. The implicit main was being emitted even when '-c' was give in #cmdline and was working differently than when '-c' given on the actual command line.
131131
- fbc: extend lifetime of temporary variables in WITH TYPE(...) expressions to the END WITH statement

src/compiler/parser-expr-variable.bas

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,12 @@ function cMemberDeref _
698698
if( lexGetToken( ) = CHAR_DOT ) then
699699
lexSkipToken( LEXCHECK_NOPERIOD )
700700

701+
'' member access on overloaded []'s return type must be UDT
702+
if( astGetDataType( varexpr ) <> FB_DATATYPE_STRUCT ) then
703+
errReport( FB_ERRMSG_EXPECTEDUDT, TRUE )
704+
exit function
705+
end if
706+
701707
'' MemberAccess
702708
varexpr = cMemberAccess( astGetFullType( varexpr ), _
703709
astGetSubType( varexpr ), varexpr )

tests/syntax/err-expected-udt.bas

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
'' FB_ERRMSG_EXPECTEDUDT
2+
3+
namespace n1
4+
type T extends object
5+
declare operator []( byval index as integer) as any ptr
6+
end type
7+
8+
sub proc
9+
dim as T x
10+
#print "-- 1 error expected"
11+
print x[0].invalid
12+
end sub
13+
end namespace
14+
15+
namespace n2
16+
type T
17+
i as T ptr
18+
end type
19+
20+
sub proc
21+
dim x as T
22+
#print "-- 1 error expected"
23+
print x.i.i
24+
end sub
25+
end namespace
26+
27+
namespace n3
28+
sub proc
29+
dim x as integer
30+
#print "-- 1 error expected"
31+
print x.invalid
32+
end sub
33+
end namespace
34+
35+
namespace n4
36+
type T
37+
i as integer
38+
end type
39+
40+
sub proc
41+
dim x as T
42+
#print "-- 1 error expected"
43+
print peek(@x).invalid
44+
end sub
45+
end namespace
46+
47+
namespace n5
48+
function f() as any ptr
49+
function = 0
50+
end function
51+
52+
sub proc
53+
#print "-- 1 error expected"
54+
print f().invalid
55+
end sub
56+
end namespace
57+
58+
namespace n6
59+
type T
60+
i as any ptr
61+
end type
62+
63+
sub proc
64+
dim x as T
65+
dim px as T ptr = @x
66+
#print "-- 1 error expected"
67+
print px->i.i
68+
end sub
69+
end namespace
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
-- 1 error expected
2+
err-expected-udt.bas(11) error 265: Symbol not a CLASS, ENUM, TYPE or UNION type, before 'invalid' in 'print x[0].invalid'
3+
-- 1 error expected
4+
err-expected-udt.bas(23) error 265: Symbol not a CLASS, ENUM, TYPE or UNION type, before '.' in 'print x.i.i'
5+
-- 1 error expected
6+
err-expected-udt.bas(31) error 265: Symbol not a CLASS, ENUM, TYPE or UNION type, before '.' in 'print x.invalid'
7+
-- 1 error expected
8+
err-expected-udt.bas(43) error 265: Symbol not a CLASS, ENUM, TYPE or UNION type, before '.' in 'print peek(@x).invalid'
9+
-- 1 error expected
10+
err-expected-udt.bas(54) error 265: Symbol not a CLASS, ENUM, TYPE or UNION type, before '.' in 'print f().invalid'
11+
-- 1 error expected
12+
err-expected-udt.bas(67) error 265: Symbol not a CLASS, ENUM, TYPE or UNION type, before '.' in 'print px->i.i'
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
-- 1 error expected
2+
err-expected-udt.bas(11) error 265: Symbol not a CLASS, ENUM, TYPE or UNION type, before 'invalid' in 'print x[0].invalid'
3+
-- 1 error expected
4+
err-expected-udt.bas(23) error 265: Symbol not a CLASS, ENUM, TYPE or UNION type, before '.' in 'print x.i.i'
5+
-- 1 error expected
6+
err-expected-udt.bas(31) error 265: Symbol not a CLASS, ENUM, TYPE or UNION type, before '.' in 'print x.invalid'
7+
-- 1 error expected
8+
err-expected-udt.bas(43) error 265: Symbol not a CLASS, ENUM, TYPE or UNION type, before '.' in 'print peek(@x).invalid'
9+
-- 1 error expected
10+
err-expected-udt.bas(54) error 265: Symbol not a CLASS, ENUM, TYPE or UNION type, before '.' in 'print f().invalid'
11+
-- 1 error expected
12+
err-expected-udt.bas(67) error 265: Symbol not a CLASS, ENUM, TYPE or UNION type, before '.' in 'print px->i.i'
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
-- 1 error expected
2+
err-expected-udt.bas(11) error 265: Symbol not a CLASS, ENUM, TYPE or UNION type, before 'invalid' in 'print x[0].invalid'
3+
-- 1 error expected
4+
err-expected-udt.bas(23) error 265: Symbol not a CLASS, ENUM, TYPE or UNION type, before '.' in 'print x.i.i'
5+
-- 1 error expected
6+
err-expected-udt.bas(31) error 265: Symbol not a CLASS, ENUM, TYPE or UNION type, before '.' in 'print x.invalid'
7+
-- 1 error expected
8+
err-expected-udt.bas(43) error 265: Symbol not a CLASS, ENUM, TYPE or UNION type, before '.' in 'print peek(@x).invalid'
9+
-- 1 error expected
10+
err-expected-udt.bas(54) error 265: Symbol not a CLASS, ENUM, TYPE or UNION type, before '.' in 'print f().invalid'
11+
-- 1 error expected
12+
err-expected-udt.bas(67) error 265: Symbol not a CLASS, ENUM, TYPE or UNION type, before '.' in 'print px->i.i'
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
-- 1 error expected
2+
err-expected-udt.bas(11) error 265: Symbol not a CLASS, ENUM, TYPE or UNION type, before 'invalid' in 'print x[0].invalid'
3+
-- 1 error expected
4+
err-expected-udt.bas(23) error 265: Symbol not a CLASS, ENUM, TYPE or UNION type, before '.' in 'print x.i.i'
5+
-- 1 error expected
6+
err-expected-udt.bas(31) error 265: Symbol not a CLASS, ENUM, TYPE or UNION type, before '.' in 'print x.invalid'
7+
-- 1 error expected
8+
err-expected-udt.bas(43) error 265: Symbol not a CLASS, ENUM, TYPE or UNION type, before '.' in 'print peek(@x).invalid'
9+
-- 1 error expected
10+
err-expected-udt.bas(54) error 265: Symbol not a CLASS, ENUM, TYPE or UNION type, before '.' in 'print f().invalid'
11+
-- 1 error expected
12+
err-expected-udt.bas(67) error 265: Symbol not a CLASS, ENUM, TYPE or UNION type, before '.' in 'print px->i.i'
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
-- 1 error expected
2+
err-expected-udt.bas(11) error 265: Symbol not a CLASS, ENUM, TYPE or UNION type, before 'invalid' in 'print x[0].invalid'
3+
-- 1 error expected
4+
err-expected-udt.bas(23) error 265: Symbol not a CLASS, ENUM, TYPE or UNION type, before '.' in 'print x.i.i'
5+
-- 1 error expected
6+
err-expected-udt.bas(31) error 265: Symbol not a CLASS, ENUM, TYPE or UNION type, before '.' in 'print x.invalid'
7+
-- 1 error expected
8+
err-expected-udt.bas(43) error 265: Symbol not a CLASS, ENUM, TYPE or UNION type, before '.' in 'print peek(@x).invalid'
9+
-- 1 error expected
10+
err-expected-udt.bas(54) error 265: Symbol not a CLASS, ENUM, TYPE or UNION type, before '.' in 'print f().invalid'
11+
-- 1 error expected
12+
err-expected-udt.bas(67) error 265: Symbol not a CLASS, ENUM, TYPE or UNION type, before '.' in 'print px->i.i'

0 commit comments

Comments
 (0)