Appearance
| 1 | namespace IR.Program is | |
| 2 | use Semantic.Symbols.Classy | |
| 3 | use Semantic.Symbols.Function | |
| 4 | ||
| 5 | /// Whether a class's method implements a trait method because its name | |
| 6 | /// and signature are the same, as .NET binds an interface method to a | |
| 7 | /// class's, where the compiler recorded it overriding another trait's | |
| 8 | /// method of the same shape instead: one class method satisfies every | |
| 9 | /// trait that declares it. | |
| 10 | class TRAIT_SIGNATURE_MATCH is | |
| 11 | /// Whether `method` implements the trait method `selector` by name | |
| 12 | /// and signature. A parameter of the selector that is a type | |
| 13 | /// parameter matches whatever is given. The return has to fit as an | |
| 14 | /// override's would, unless the selector's is a type parameter: a | |
| 15 | /// same-named method returning something else hides rather than | |
| 16 | /// implements. | |
| 17 | /// | |
| 18 | /// - method: an instance method of a class or struct | |
| 19 | /// - selector: a trait method | |
| 20 | implements(method: Function, selector: Function) -> bool static is | |
| 21 | if !(cast Classy?(selector.owner)?.is_trait ?? false) \/ method.name !~ selector.name \/ !method.is_instance then | |
| 22 | return false | |
| 23 | fi | |
| 24 | ||
| 25 | if !(selector.return_type?.is_type_variable ?? false) /\ !method.has_overriding_return_type(selector) then | |
| 26 | return false | |
| 27 | fi | |
| 28 | ||
| 29 | let mine = method.arguments | |
| 30 | let theirs = selector.arguments | |
| 31 | ||
| 32 | if mine.count != theirs.count then | |
| 33 | return false | |
| 34 | fi | |
| 35 | ||
| 36 | for i in 0..mine.count do | |
| 37 | if !theirs[i].is_type_variable /\ (!mine[i].matches(theirs[i]) \/ !theirs[i].matches(mine[i])) then | |
| 38 | return false | |
| 39 | fi | |
| 40 | od | |
| 41 | ||
| 42 | return true | |
| 43 | si | |
| 44 | si | |
| 45 | si |