Skip to content

Commit 228ec6f

Browse files
committed
parser: Allow UDT().field too, not just (UDT()).field (#757)
1 parent 2e05d06 commit 228ec6f

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Version 1.01.0
99
- WITH compounds now also accept type<UDT>(...) and UDT(...) expressions
1010
- Constant 0 integers can now be assigned to pointers no matter what integer type it is. Previously it didn't work with [U]LongInts on 32bit and [U]Longs on 64bit.
1111
- Constant 0 pointers can now be assigned to any integer type. Previously this was only allowed with integer types matching the pointer size (32bit or 64bit).
12+
- #757: It's now possible to do UDT().field instead of (UDT()).field (field accesses on anonymous UDTs with constructors)
1213
- Bindings (new/updated, including 64bit support):
1314
Allegro 4.4.2 (allegro.bi)
1415
algif 1.3 (allegro/algif.bi)

src/compiler/parser-expr-atom.bas

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,15 +304,15 @@ private function hFindId _
304304
if( symbGetCompCtorHead( sym ) ) then
305305
'' skip ID, ctorCall() is also used by type<>(...)
306306
lexSkipToken( )
307-
return cCtorCall( sym )
307+
return cStrIdxOrMemberDeref( cCtorCall( sym ) )
308308
end if
309309

310310
case FB_SYMBCLASS_TYPEDEF
311311
'' typedef of a TYPE/CLASS?
312312
if( symbHasCtor( sym ) ) then
313313
'' skip ID, ctorCall() is also used by type<>(...)
314314
lexSkipToken( )
315-
return cCtorCall( symbGetSubtype( sym ) )
315+
return cStrIdxOrMemberDeref( cCtorCall( symbGetSubtype( sym ) ) )
316316
end if
317317

318318
end select

tests/structs/anon-access.bas

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,33 @@ constructor CtorUdt( )
1616
b = 456
1717
end constructor
1818

19+
type PodUdtAlias as PodUdt
20+
type CtorUdtAlias as CtorUdt
21+
1922
sub test cdecl( )
2023
CU_ASSERT( (type<PodUdt>( 123 )).i = 123 )
2124
CU_ASSERT( type<PodUdt>( 123 ).i = 123 )
25+
26+
CU_ASSERT( (type<PodUdtAlias>( 123 )).i = 123 )
27+
CU_ASSERT( type<PodUdtAlias>( 123 ).i = 123 )
28+
29+
CU_ASSERT( (CtorUdt( )).a = 123 )
30+
CU_ASSERT( (CtorUdt( )).b = 456 )
31+
CU_ASSERT( CtorUdt( ).a = 123 )
32+
CU_ASSERT( CtorUdt( ).b = 456 )
33+
CU_ASSERT( (type<CtorUdt>( )).a = 123 )
34+
CU_ASSERT( (type<CtorUdt>( )).b = 456 )
35+
CU_ASSERT( type<CtorUdt>( ).a = 123 )
36+
CU_ASSERT( type<CtorUdt>( ).b = 456 )
37+
38+
CU_ASSERT( (CtorUdtAlias( )).a = 123 )
39+
CU_ASSERT( (CtorUdtAlias( )).b = 456 )
40+
CU_ASSERT( CtorUdtAlias( ).a = 123 )
41+
CU_ASSERT( CtorUdtAlias( ).b = 456 )
42+
CU_ASSERT( (type<CtorUdtAlias>( )).a = 123 )
43+
CU_ASSERT( (type<CtorUdtAlias>( )).b = 456 )
44+
CU_ASSERT( type<CtorUdtAlias>( ).a = 123 )
45+
CU_ASSERT( type<CtorUdtAlias>( ).b = 456 )
2246
end sub
2347

2448
private sub test3538470 cdecl( )

0 commit comments

Comments
 (0)