@@ -154,68 +154,81 @@ class CSCompiler_Expr extends CSCompiler_Base {
154154 )
155155 })
156156 }
157- case TField (e , fa ):
158- {
159- haxeExpr : expr ,
160- def : CSExprStatement ({
161- haxeExpr : expr ,
162- type : csType ,
163- def : switch fa {
164- case FInstance (c , params , cf ):
165- CSField (
166- compileToCSExpr (e ),
167- CSFInstance (
168- compiler .typeComp .compileClassTypePath (c .get ()),
169- compiler .typeComp .compileTypeParams (params ),
170- cf .get ().name
171- )
172- );
173- case FStatic (c , cf ):
174- CSField (
175- compileToCSExpr (e ),
176- CSFStatic (
177- compiler .typeComp .compileClassTypePath (c .get ()),
178- // C# type inference should be able to infer generic types
179- // from arguments, but it also allows the types to be explicit.
180- // We might need that in some situation where inference is not enough?
181- [],
182- cf .get ().name
183- )
184- );
185- case FAnon (cf ):
186- // We rely on dynamic access to read anon fields, because for now,
187- // they will be backed with `haxe.lang.DynamicObject` anyway
188- compileDynamicGetField (expr , cf .get ().name );
189- case FDynamic (s ):
190- compileDynamicGetField (expr , s );
191- case FClosure (c , cf ):
192- // TODO: do we need to generate different code than FInstance?
193- CSField (
194- compileToCSExpr (e ),
195- CSFInstance (
196- c ?. c != null ? compiler .typeComp .compileClassTypePath (c .c .get ()) : ' object' , // TODO: Should it be 'object' if we don't have any class type there?
197- c ?. params != null ? compiler .typeComp .compileTypeParams (c .params ) : [],
198- cf .get ().name
199- )
200- );
201- case FEnum (en , ef ):
202- CSField (
203- compileToCSExpr (e ),
204- CSFInstance (
205- compiler .typeComp .compileEnumTypePath (en .get ()),
206- [],
207- ef .name
208- )
209- );
157+ case TField (e , fa ): {
158+ switch fa {
159+ case FInstance (classTypeRef , _ , _ ) | FStatic (classTypeRef , _ ): {
160+ compiler .addModuleTypeForCompilation (TClassDecl (classTypeRef ));
210161 }
211- })
162+ case FEnum (enumRef , _ ): {
163+ compiler .addModuleTypeForCompilation (TEnumDecl (enumRef ));
164+ }
165+ case _ :
166+ }
167+ {
168+ haxeExpr : expr ,
169+ def : CSExprStatement ({
170+ haxeExpr : expr ,
171+ type : csType ,
172+ def : switch fa {
173+ case FInstance (c , params , cf ):
174+ CSField (
175+ compileToCSExpr (e ),
176+ CSFInstance (
177+ compiler .typeComp .compileClassTypePath (c .get ()),
178+ compiler .typeComp .compileTypeParams (params ),
179+ cf .get ().name
180+ )
181+ );
182+ case FStatic (c , cf ):
183+ CSField (
184+ compileToCSExpr (e ),
185+ CSFStatic (
186+ compiler .typeComp .compileClassTypePath (c .get ()),
187+ // C# type inference should be able to infer generic types
188+ // from arguments, but it also allows the types to be explicit.
189+ // We might need that in some situation where inference is not enough?
190+ [],
191+ cf .get ().name
192+ )
193+ );
194+ case FAnon (cf ):
195+ // We rely on dynamic access to read anon fields, because for now,
196+ // they will be backed with `haxe.lang.DynamicObject` anyway
197+ compileDynamicGetField (expr , cf .get ().name );
198+ case FDynamic (s ):
199+ compileDynamicGetField (expr , s );
200+ case FClosure (c , cf ):
201+ // TODO: do we need to generate different code than FInstance?
202+ CSField (
203+ compileToCSExpr (e ),
204+ CSFInstance (
205+ c ?. c != null ? compiler .typeComp .compileClassTypePath (c .c .get ()) : ' object' , // TODO: Should it be 'object' if we don't have any class type there?
206+ c ?. params != null ? compiler .typeComp .compileTypeParams (c .params ) : [],
207+ cf .get ().name
208+ )
209+ );
210+ case FEnum (en , ef ):
211+ CSField (
212+ compileToCSExpr (e ),
213+ CSFInstance (
214+ compiler .typeComp .compileEnumTypePath (en .get ()),
215+ [],
216+ ef .name
217+ )
218+ );
219+ }
220+ })
221+ }
212222 }
213- case TTypeExpr (m ): {
223+
224+ case TTypeExpr (moduleType ): {
225+ compiler .addModuleTypeForCompilation (moduleType );
226+
214227 // Note:
215228 // we don't have access to type params here,
216229 // so they are always empty.
217230 // TODO: or can we resolve them from the expression type?
218- switch m {
231+ switch moduleType {
219232 case TClassDecl (c ):
220233 {
221234 haxeExpr : expr ,
@@ -298,9 +311,8 @@ class CSCompiler_Expr extends CSCompiler_Base {
298311 })
299312 }
300313 }
301- case TCall (e , el ):
302- // TODO: do we need to generate something different if using @:nativeFunctionCode here? (reflaxe feature)
303- {
314+ case TCall (e , el ): {
315+ // TODO: do we need to generate something different if using @:nativeFunctionCode here? (reflaxe feature)
304316 haxeExpr : expr ,
305317 def : CSExprStatement ({
306318 haxeExpr : expr ,
@@ -315,19 +327,22 @@ class CSCompiler_Expr extends CSCompiler_Base {
315327 )
316328 })
317329 }
318- case TNew (classTypeRef , params , el ):
319- // TODO: do we need to generate something different if using @:nativeFunctionCode here? (reflaxe feature)
320- {
321- haxeExpr : expr ,
322- def : CSExprStatement ( {
330+ case TNew (classTypeRef , params , el ): {
331+ compiler . addModuleTypeForCompilation ( TClassDecl ( classTypeRef ));
332+
333+ // TODO: do we need to generate something different if using @:nativeFunctionCode here? (reflaxe feature)
334+ {
323335 haxeExpr : expr ,
324- type : csType ,
325- def : CSNew (
326- compiler .typeComp .compileClassTypePath (classTypeRef .get ()),
327- params .map (p -> compiler .compileType (p , expr .pos )),
328- el .map (e -> compileToCSExpr (e ))
329- )
330- })
336+ def : CSExprStatement ({
337+ haxeExpr : expr ,
338+ type : csType ,
339+ def : CSNew (
340+ compiler .typeComp .compileClassTypePath (classTypeRef .get ()),
341+ params .map (p -> compiler .compileType (p , expr .pos )),
342+ el .map (e -> compileToCSExpr (e ))
343+ )
344+ })
345+ }
331346 }
332347 case TUnop (op , postFix , e ): {
333348 haxeExpr : expr ,
@@ -428,9 +443,10 @@ class CSCompiler_Expr extends CSCompiler_Base {
428443 case TCast (subExpr , maybeModuleType ): {
429444 if (maybeModuleType == null ) {
430445 compileToCSStatement (subExpr );
431- }
432- else {
433- final type = TypeTools .fromModuleType (maybeModuleType );
446+ } else {
447+ compiler .addModuleTypeForCompilation (maybeModuleType );
448+
449+ final type = #if macro TypeTools .fromModuleType (maybeModuleType ) #else null #end;
434450 {
435451 haxeExpr : expr ,
436452 def : CSCast (
0 commit comments