@@ -260,18 +260,50 @@ class ModelBuilder
260
260
end
261
261
262
262
# Return the static type associated to the node `ntype`.
263
- # `mmodule` and `mclassdef` is the context where the call is made (used to understand formal types)
263
+ #
264
+ # `mclassdef` is the context where the call is made (used to understand
265
+ # formal types).
264
266
# In case of problem, an error is displayed on `ntype` and null is returned.
265
- # FIXME: the name "resolve_mtype" is awful
266
- fun resolve_mtype_unchecked (mmodule : MModule , mclassdef : nullable MClassDef , ntype : AType , with_virtual : Bool ): nullable MType
267
+ #
268
+ # Same as `resolve_mtype_unchecked3`, but get the context (module, class and
269
+ # anchor) from `mclassdef`.
270
+ #
271
+ # SEE: `resolve_mtype`
272
+ # SEE: `resolve_mtype3_unchecked`
273
+ #
274
+ # FIXME: Find a better name for this method.
275
+ fun resolve_mtype_unchecked (mclassdef : MClassDef , ntype : AType , with_virtual : Bool ): nullable MType
276
+ do
277
+ return resolve_mtype3_unchecked (
278
+ mclassdef .mmodule ,
279
+ mclassdef .mclass ,
280
+ mclassdef .bound_mtype ,
281
+ ntype ,
282
+ with_virtual
283
+ )
284
+ end
285
+
286
+ # Return the static type associated to the node `ntype`.
287
+ #
288
+ # `mmodule`, `mclass` and `anchor` compose the context where the call is
289
+ # made (used to understand formal types).
290
+ # In case of problem, an error is displayed on `ntype` and null is returned.
291
+ #
292
+ # Note: The “3” is for 3 contextual parameters.
293
+ #
294
+ # SEE: `resolve_mtype`
295
+ # SEE: `resolve_mtype_unchecked`
296
+ #
297
+ # FIXME: Find a better name for this method.
298
+ fun resolve_mtype3_unchecked (mmodule : MModule , mclass : nullable MClass , anchor : nullable MClassType , ntype : AType , with_virtual : Bool ): nullable MType
267
299
do
268
300
var qid = ntype .n_qid
269
301
var name = qid .n_id .text
270
302
var res : MType
271
303
272
304
# Check virtual type
273
- if mclassdef != null and with_virtual then
274
- var prop = try_get_mproperty_by_name (ntype , mclassdef , name ).as (nullable MVirtualTypeProp )
305
+ if anchor != null and with_virtual then
306
+ var prop = try_get_mproperty_by_name2 (ntype , mmodule , anchor , name ).as (nullable MVirtualTypeProp )
275
307
if prop != null then
276
308
if not ntype .n_types .is_empty then
277
309
error (ntype , "Type Error: formal type ` {name } ` cannot have formal parameters. " )
@@ -284,8 +316,8 @@ class ModelBuilder
284
316
end
285
317
286
318
# Check parameter type
287
- if mclassdef != null then
288
- for p in mclassdef . mclass .mparameters do
319
+ if mclass != null then
320
+ for p in mclass .mparameters do
289
321
if p .name != name then continue
290
322
291
323
if not ntype .n_types .is_empty then
@@ -321,7 +353,7 @@ class ModelBuilder
321
353
else
322
354
var mtypes = new Array [MType ]
323
355
for nt in ntype .n_types do
324
- var mt = resolve_mtype_unchecked (mmodule , mclassdef , nt , with_virtual )
356
+ var mt = resolve_mtype3_unchecked (mmodule , mclass , anchor , nt , with_virtual )
325
357
if mt == null then return null # Forward error
326
358
mtypes .add (mt )
327
359
end
@@ -415,13 +447,44 @@ class ModelBuilder
415
447
private var bad_class_names = new MultiHashMap [MModule , String ]
416
448
417
449
# Return the static type associated to the node `ntype`.
418
- # `mmodule` and `mclassdef` is the context where the call is made (used to understand formal types)
450
+ #
451
+ # `mclassdef` is the context where the call is made (used to understand
452
+ # formal types).
419
453
# In case of problem, an error is displayed on `ntype` and null is returned.
420
- # FIXME: the name "resolve_mtype" is awful
421
- fun resolve_mtype (mmodule : MModule , mclassdef : nullable MClassDef , ntype : AType ): nullable MType
454
+ #
455
+ # Same as `resolve_mtype3`, but get the context (module, class and ) from
456
+ # `mclassdef`.
457
+ #
458
+ # SEE: `resolve_mtype3`
459
+ # SEE: `resolve_mtype_unchecked`
460
+ #
461
+ # FIXME: Find a better name for this method.
462
+ fun resolve_mtype (mclassdef : MClassDef , ntype : AType ): nullable MType
463
+ do
464
+ return resolve_mtype3 (
465
+ mclassdef .mmodule ,
466
+ mclassdef .mclass ,
467
+ mclassdef .bound_mtype ,
468
+ ntype
469
+ )
470
+ end
471
+
472
+ # Return the static type associated to the node `ntype`.
473
+ #
474
+ # `mmodule`, `mclass` and `anchor` compose the context where the call is
475
+ # made (used to understand formal types).
476
+ # In case of problem, an error is displayed on `ntype` and null is returned.
477
+ #
478
+ # Note: The “3” is for 3 contextual parameters.
479
+ #
480
+ # SEE: `resolve_mtype`
481
+ # SEE: `resolve_mtype_unchecked`
482
+ #
483
+ # FIXME: Find a better name for this method.
484
+ fun resolve_mtype3 (mmodule : MModule , mclass : nullable MClass , anchor : nullable MClassType , ntype : AType ): nullable MType
422
485
do
423
486
var mtype = ntype .mtype
424
- if mtype == null then mtype = resolve_mtype_unchecked (mmodule , mclassdef , ntype , true )
487
+ if mtype == null then mtype = resolve_mtype3_unchecked (mmodule , mclass , anchor , ntype , true )
425
488
if mtype == null then return null # Forward error
426
489
427
490
if ntype .checked_mtype then return mtype
@@ -432,10 +495,8 @@ class ModelBuilder
432
495
if intro == null then return null # skip error
433
496
var bound = intro .bound_mtype .arguments [i ]
434
497
var nt = ntype .n_types [i ]
435
- var mt = resolve_mtype (mmodule , mclassdef , nt )
498
+ var mt = resolve_mtype3 (mmodule , mclass , anchor , nt )
436
499
if mt == null then return null # forward error
437
- var anchor
438
- if mclassdef != null then anchor = mclassdef .bound_mtype else anchor = null
439
500
if not check_subtype (nt , mmodule , anchor , mt , bound ) then
440
501
error (nt , "Type Error: expected ` {bound } `, got ` {mt } `. " )
441
502
return null
0 commit comments