lisette-syntax 0.11.3

Little language inspired by Rust that compiles to Go
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
use rustc_hash::{FxHashMap as HashMap, FxHashSet as HashSet};

use ecow::EcoString;

use crate::ast::{Annotation, EnumVariant, Generic, Literal, Span, StructFields};
use crate::types;
use crate::types::{
    FunctionParameter, Symbol, Type, build_substitution_map, substitute, type_args_match_params,
};

#[derive(Debug, Clone)]
pub struct Definition {
    pub visibility: Visibility,
    pub ty: Type,
    pub name_span: Option<Span>,
    pub doc: Option<String>,
    pub body: DefinitionBody,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum TypeAttribute {
    Display,
    ClosedDomain,
    AnonStruct,
    /// Go struct that looks flat but hides an embed bindgen could not emit, so it
    /// cannot be soundly embedded.
    HiddenEmbed,
    Serialized,
    ZeroSafe,
    /// Go type whose zero value is documented broken, so it must come from
    /// its constructor.
    ZeroUnsafe,
    HiddenFields,
}

pub type Attributes = HashSet<TypeAttribute>;

#[derive(Debug, Clone)]
pub enum ValueKind {
    Runtime,
    ConstantDeclaration,
    Constant(Literal),
}

#[derive(Debug, Clone)]
pub enum DefinitionBody {
    TypeAlias {
        generics: Vec<Generic>,
        alias: AliasKind,
        methods: Methods,
        attributes: Attributes,
    },
    Enum {
        generics: Vec<Generic>,
        variants: Vec<EnumVariant>,
        methods: Methods,
        attributes: Attributes,
    },
    Struct {
        generics: Vec<Generic>,
        fields: StructFields,
        methods: Methods,
        attributes: Attributes,
    },
    Interface {
        definition: Interface,
    },
    Value {
        kind: ValueKind,
        allowed_lints: Vec<String>,
        go_hints: Vec<String>,
        go_name: Option<String>,
        /// Go's full type-parameter list for a `#[go(collapsed_type_params)]`
        /// function, in declaration order, each entry as a Lisette type (e.g.
        /// `"Slice<E>, E"`). Lets emit rebuild Go's type arguments when the
        /// collapsed Lisette list cannot be projected onto Go's positionally.
        go_type_param_recipe: Option<String>,
    },
}

#[derive(Debug, Clone)]
pub enum AliasKind {
    Opaque(Annotation),
    Transparent {
        annotation: Annotation,
        target: Type,
    },
}

impl AliasKind {
    pub fn annotation(&self) -> &Annotation {
        match self {
            Self::Opaque(annotation) | Self::Transparent { annotation, .. } => annotation,
        }
    }
}

impl DefinitionBody {
    pub fn generics(&self) -> Option<&[Generic]> {
        match self {
            Self::TypeAlias { generics, .. }
            | Self::Enum { generics, .. }
            | Self::Struct { generics, .. } => Some(generics),
            Self::Interface { definition } => Some(&definition.generics),
            Self::Value { .. } => None,
        }
    }

    pub fn generics_mut(&mut self) -> Option<&mut [Generic]> {
        match self {
            Self::TypeAlias { generics, .. }
            | Self::Enum { generics, .. }
            | Self::Struct { generics, .. } => Some(generics),
            Self::Interface { definition } => Some(&mut definition.generics),
            Self::Value { .. } => None,
        }
    }
}

impl Definition {
    /// A newtype is a single-field, non-generic tuple struct. Relevant
    /// because Go compiles newtypes to named scalar types, so `.0` is a cast
    /// rather than a field access, it cannot be assigned to, and taking
    /// its address is invalid.
    pub fn is_newtype(&self) -> bool {
        matches!(
            &self.body,
            DefinitionBody::Struct {
                fields: StructFields::Tuple(fields),
                generics,
                ..
            } if fields.len() == 1 && generics.is_empty()
        )
    }

    pub fn is_pointer_backed_newtype<'d, F>(&self, lookup: F) -> bool
    where
        F: Fn(&str) -> Option<&'d Definition>,
    {
        self.is_newtype()
            && matches!(
                &self.body,
                DefinitionBody::Struct {
                    fields: StructFields::Tuple(fields),
                    ..
                } if types::peel_alias(&fields[0].ty, lookup).is_ref()
            )
    }

    pub fn instantiate_alias_target(&self, params: &[Type], writable: bool) -> Option<Type> {
        let DefinitionBody::TypeAlias {
            generics,
            alias: AliasKind::Transparent { target, .. },
            ..
        } = &self.body
        else {
            return None;
        };
        let map = build_substitution_map(generics, params);
        if writable {
            Some(substitute(&target.clone().make_writable(), &map))
        } else {
            Some(substitute(target, &map))
        }
    }

    pub fn instantiate_underlying(&self, params: &[Type], writable: bool) -> Option<Type> {
        if let Some(target) = self.instantiate_alias_target(params, writable) {
            return Some(target);
        }
        match &self.body {
            DefinitionBody::Struct {
                fields: StructFields::Tuple(fields),
                ..
            } if self.is_newtype() => Some(if writable {
                fields[0].ty.clone()
            } else {
                fields[0].ty.demoted()
            }),
            _ => None,
        }
    }

    /// Returns the callable type of a tuple struct constructor.
    ///
    /// The constructor is derived from the struct's resolved fields and type
    /// rather than stored separately, so it cannot become stale when either
    /// source changes.
    pub fn constructor_type(&self) -> Option<Type> {
        let DefinitionBody::Struct {
            fields: StructFields::Tuple(fields),
            generics,
            ..
        } = &self.body
        else {
            return None;
        };

        let return_type = self.ty.unwrap_forall().clone();
        let function = Type::function(
            fields
                .iter()
                .map(|field| FunctionParameter::new(field.ty.clone(), false))
                .collect(),
            Default::default(),
            return_type.into(),
        );

        Some(if generics.is_empty() {
            function
        } else {
            Type::Forall {
                vars: generics
                    .iter()
                    .map(|generic| generic.name.clone())
                    .collect(),
                body: Box::new(function),
            }
        })
    }

    pub fn is_transparent_type_alias(&self) -> bool {
        matches!(
            self.body,
            DefinitionBody::TypeAlias {
                alias: AliasKind::Transparent { .. },
                ..
            }
        )
    }

    pub fn allowed_lints(&self) -> &[String] {
        match &self.body {
            DefinitionBody::Value { allowed_lints, .. } => allowed_lints,
            _ => &[],
        }
    }

    pub fn go_hints(&self) -> &[String] {
        match &self.body {
            DefinitionBody::Value { go_hints, .. } => go_hints,
            _ => &[],
        }
    }

    pub fn go_name(&self) -> Option<&str> {
        match &self.body {
            DefinitionBody::Value { go_name, .. } => go_name.as_deref(),
            _ => None,
        }
    }

    pub fn go_type_param_recipe(&self) -> Option<&str> {
        match &self.body {
            DefinitionBody::Value {
                go_type_param_recipe,
                ..
            } => go_type_param_recipe.as_deref(),
            _ => None,
        }
    }

    pub fn const_value(&self) -> Option<&Literal> {
        match &self.body {
            DefinitionBody::Value {
                kind: ValueKind::Constant(value),
                ..
            } => Some(value),
            _ => None,
        }
    }

    pub fn is_const(&self) -> bool {
        matches!(
            self.body,
            DefinitionBody::Value {
                kind: ValueKind::ConstantDeclaration | ValueKind::Constant(_),
                ..
            }
        )
    }

    pub fn methods_mut(&mut self) -> Option<&mut Methods> {
        match &mut self.body {
            DefinitionBody::Struct { methods, .. } => Some(methods),
            DefinitionBody::TypeAlias { methods, .. } => Some(methods),
            DefinitionBody::Enum { methods, .. } => Some(methods),
            DefinitionBody::Interface { definition } => Some(&mut definition.methods),
            DefinitionBody::Value { .. } => None,
        }
    }

    pub fn methods(&self) -> Option<&Methods> {
        match &self.body {
            DefinitionBody::Struct { methods, .. }
            | DefinitionBody::TypeAlias { methods, .. }
            | DefinitionBody::Enum { methods, .. } => Some(methods),
            DefinitionBody::Interface { definition } => Some(&definition.methods),
            DefinitionBody::Value { .. } => None,
        }
    }

    pub fn is_ufcs_method(&self, method: &str) -> bool {
        let (methods, base_generics_count) = match &self.body {
            DefinitionBody::Struct {
                methods, generics, ..
            }
            | DefinitionBody::Enum {
                methods, generics, ..
            }
            | DefinitionBody::TypeAlias {
                methods, generics, ..
            } => (methods, generics.len()),
            DefinitionBody::Interface { .. } | DefinitionBody::Value { .. } => return false,
        };
        methods
            .get(method)
            .is_some_and(|method| is_ufcs_method_type(&method.ty, base_generics_count))
    }

    fn attributes(&self) -> Option<&Attributes> {
        match &self.body {
            DefinitionBody::Struct { attributes, .. }
            | DefinitionBody::Enum { attributes, .. }
            | DefinitionBody::TypeAlias { attributes, .. } => Some(attributes),
            _ => None,
        }
    }

    pub fn is_display(&self) -> bool {
        self.attributes()
            .is_some_and(|a| a.contains(&TypeAttribute::Display))
    }

    pub fn is_zero_safe(&self) -> bool {
        self.attributes()
            .is_some_and(|a| a.contains(&TypeAttribute::ZeroSafe))
    }

    pub fn is_zero_unsafe(&self) -> bool {
        self.attributes()
            .is_some_and(|a| a.contains(&TypeAttribute::ZeroUnsafe))
    }

    pub fn has_hidden_fields(&self) -> bool {
        self.attributes()
            .is_some_and(|a| a.contains(&TypeAttribute::HiddenFields))
    }

    pub fn is_closed_domain(&self) -> bool {
        self.attributes()
            .is_some_and(|a| a.contains(&TypeAttribute::ClosedDomain))
    }

    pub fn is_serialized(&self) -> bool {
        self.attributes()
            .is_some_and(|a| a.contains(&TypeAttribute::Serialized))
    }

    pub fn is_anon_struct(&self) -> bool {
        self.attributes()
            .is_some_and(|a| a.contains(&TypeAttribute::AnonStruct))
    }

    pub fn has_hidden_embed(&self) -> bool {
        self.attributes()
            .is_some_and(|a| a.contains(&TypeAttribute::HiddenEmbed))
    }

    pub fn is_type_definition(&self) -> bool {
        matches!(
            self.body,
            DefinitionBody::Struct { .. }
                | DefinitionBody::Enum { .. }
                | DefinitionBody::TypeAlias { .. }
        )
    }

    pub fn is_type_alias(&self) -> bool {
        matches!(self.body, DefinitionBody::TypeAlias { .. })
    }

    pub fn is_value(&self, qualified_name: &str) -> bool {
        matches!(self.body, DefinitionBody::Value { .. })
            && self.ty.unwrap_forall().get_qualified_id() != Some(qualified_name)
    }
}

fn is_ufcs_method_type(method_ty: &Type, base_generics_count: usize) -> bool {
    let Type::Forall { vars, body } = method_ty else {
        return base_generics_count > 0;
    };

    if vars.len() > base_generics_count {
        return true;
    }

    if let Type::Function(function) = body.as_ref()
        && let Some(receiver) = function.params.first()
        && let Type::Nominal {
            params: receiver_params,
            ..
        } = receiver.ty.strip_refs()
        && !type_args_match_params(&receiver_params, vars.iter())
    {
        return true;
    }

    false
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum MethodOrigin {
    Declared,
    Synthesized,
}

#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Method {
    pub source_name: EcoString,
    pub ty: Type,
    pub visibility: Visibility,
    pub origin: MethodOrigin,
    pub name_span: Option<Span>,
    pub doc: Option<String>,
    pub allowed_lints: Vec<String>,
    pub go_hints: Vec<String>,
}

impl Method {
    pub fn with_type(&self, ty: Type) -> Self {
        Self { ty, ..self.clone() }
    }

    fn with_receiver_placeholder(self) -> Self {
        let Self {
            source_name,
            ty,
            visibility,
            origin,
            name_span,
            doc,
            allowed_lints,
            go_hints,
        } = self;
        Self {
            source_name,
            ty: ty.with_receiver_placeholder(),
            visibility,
            origin,
            name_span,
            doc,
            allowed_lints,
            go_hints,
        }
    }
}

pub type Methods = HashMap<EcoString, Method>;

#[derive(Debug, Clone, PartialEq)]
pub struct InterfaceInstance {
    pub ty: Type,
    pub parent_of: Option<Symbol>,
}

/// Instantiate an interface and its complete parent hierarchy exactly once.
/// Package-qualified structural identity prevents same-named interfaces from
/// collapsing, while the active path guard terminates malformed cycles.
pub fn interface_instances<'d, F>(interface_ty: &Type, lookup: F) -> Vec<InterfaceInstance>
where
    F: Copy + Fn(&str) -> Option<&'d Definition>,
{
    fn collect<'d, F>(
        interface_ty: &Type,
        parent_of: Option<&Symbol>,
        lookup: F,
        visited: &mut HashSet<String>,
        visiting: &mut HashSet<Symbol>,
        instances: &mut Vec<InterfaceInstance>,
    ) where
        F: Copy + Fn(&str) -> Option<&'d Definition>,
    {
        let resolved = types::peel_alias(interface_ty, lookup);
        let Type::Nominal { id, params, .. } = &resolved else {
            return;
        };
        // `Display` intentionally omits package qualification, so it cannot
        // distinguish same-named interfaces from different packages.
        if !visited.insert(format!("{resolved:?}")) || !visiting.insert(id.clone()) {
            return;
        }
        let Some(Definition {
            body: DefinitionBody::Interface { definition },
            ..
        }) = lookup(id)
        else {
            visiting.remove(id);
            return;
        };
        let map = build_substitution_map(&definition.generics, params);
        instances.push(InterfaceInstance {
            ty: resolved.clone(),
            parent_of: parent_of.cloned(),
        });
        for parent in &definition.parents {
            collect(
                &substitute(parent, &map),
                Some(id),
                lookup,
                visited,
                visiting,
                instances,
            );
        }
        visiting.remove(id);
    }

    let mut instances = Vec::new();
    collect(
        interface_ty,
        None,
        lookup,
        &mut HashSet::default(),
        &mut HashSet::default(),
        &mut instances,
    );
    instances
}

#[derive(Debug, Clone, PartialEq)]
pub struct InterfaceRequirement {
    pub declaring_interface: Symbol,
    pub parent_of: Option<Symbol>,
    pub name: EcoString,
    /// The method as declared. Its type determines the generic declaration's
    /// physical ABI even when substitution reveals a special logical type.
    pub method: Method,
    /// The logical signature after applying all interface type arguments.
    pub ty: Type,
}

/// Flatten an interface and its instantiated parents into declaration-tagged
/// method requirements. Cycles and repeated generic instantiations are handled
/// here so registration, inference, and emission cannot disagree about the
/// inherited signatures.
pub fn interface_requirements<'d, F>(interface_ty: &Type, lookup: F) -> Vec<InterfaceRequirement>
where
    F: Copy + Fn(&str) -> Option<&'d Definition>,
{
    let mut requirements = Vec::new();
    for instance in interface_instances(interface_ty, lookup) {
        let Type::Nominal { id, params, .. } = instance.ty else {
            continue;
        };
        let Some(Definition {
            body: DefinitionBody::Interface { definition },
            ..
        }) = lookup(&id)
        else {
            continue;
        };
        let map = build_substitution_map(&definition.generics, &params);
        requirements.extend(
            definition
                .methods
                .iter()
                .map(|(name, method)| InterfaceRequirement {
                    declaring_interface: id.clone(),
                    parent_of: instance.parent_of.clone(),
                    name: name.clone(),
                    method: method.clone(),
                    ty: substitute(&method.ty, &map),
                }),
        );
    }
    requirements
}

/// Resolve the complete method set for a type, including inherited and alias methods.
pub fn methods_for_type<'d, F>(
    ty: &Type,
    trait_bounds: &HashMap<Symbol, Vec<Type>>,
    lookup: F,
) -> Methods
where
    F: Copy + Fn(&str) -> Option<&'d Definition>,
{
    fn collect<'d, F>(
        ty: &Type,
        trait_bounds: &HashMap<Symbol, Vec<Type>>,
        lookup: F,
        visited: &mut HashSet<String>,
    ) -> Methods
    where
        F: Copy + Fn(&str) -> Option<&'d Definition>,
    {
        let stripped = ty.strip_refs();
        let Some(qualified_name) = method_lookup_key(&stripped) else {
            return Methods::default();
        };

        if !visited.insert(qualified_name.as_str().to_string()) {
            return Methods::default();
        }

        if lookup(&qualified_name)
            .is_some_and(|definition| matches!(definition.body, DefinitionBody::Interface { .. }))
        {
            return interface_requirements(&stripped, lookup)
                .into_iter()
                .map(|requirement| {
                    (
                        requirement.name,
                        requirement
                            .method
                            .with_type(requirement.ty)
                            .with_receiver_placeholder(),
                    )
                })
                .collect();
        }

        if let Some(bounds) = trait_bounds.get(&qualified_name) {
            return bounds
                .iter()
                .flat_map(|bound| collect(bound, trait_bounds, lookup, visited))
                .collect();
        }

        let mut methods = lookup(&qualified_name)
            .and_then(Definition::methods)
            .cloned()
            .unwrap_or_default();

        if lookup(&qualified_name).is_some_and(Definition::is_transparent_type_alias) {
            let underlying = types::peel_alias(&stripped, lookup);
            if underlying != stripped {
                for (name, method) in collect(&underlying, trait_bounds, lookup, visited) {
                    methods.entry(name).or_insert(method);
                }
            }
        }

        methods
    }

    collect(ty, trait_bounds, lookup, &mut HashSet::default())
}

fn method_lookup_key(ty: &Type) -> Option<Symbol> {
    match ty {
        Type::Nominal { id, .. } => Some(id.clone()),
        Type::Compound { kind, .. } => Some(Symbol::from_parts("prelude", kind.leaf_name())),
        Type::Simple(kind) => Some(Symbol::from_parts("prelude", kind.leaf_name())),
        Type::Array { .. } => Some(Symbol::from_parts("prelude", "Array")),
        _ => None,
    }
}

#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum Visibility {
    Public,
    Private,
    Local,
}

impl Visibility {
    pub fn is_public(&self) -> bool {
        matches!(self, Visibility::Public)
    }
}

#[derive(Debug, Clone, PartialEq)]
pub struct Interface {
    pub generics: Vec<Generic>,
    pub parents: Vec<Type>,
    pub methods: Methods,
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::types::Symbol;

    fn generic(name: &str) -> Generic {
        Generic::new(name, vec![], Span::dummy())
    }

    fn receiver(params: Vec<Type>) -> Type {
        Type::Nominal {
            id: Symbol::from_raw("m.Box"),
            params,
            writable: false,
        }
    }

    fn method(vars: &[&str], receiver: Type) -> Type {
        let function = Type::function(
            vec![FunctionParameter::new(receiver, false)],
            Default::default(),
            Box::new(Type::unit()),
        );
        Type::Forall {
            vars: vars.iter().map(|name| EcoString::from(*name)).collect(),
            body: Box::new(function),
        }
    }

    fn definition(method_ty: Type) -> Definition {
        Definition {
            visibility: Visibility::Public,
            ty: receiver(vec![Type::Parameter("T".into())]),
            name_span: None,
            doc: None,
            body: DefinitionBody::Struct {
                generics: vec![generic("T")],
                fields: StructFields::Record(vec![]),
                methods: HashMap::from_iter([(
                    "map".into(),
                    Method {
                        source_name: "map".into(),
                        ty: method_ty,
                        visibility: Visibility::Public,
                        origin: MethodOrigin::Declared,
                        name_span: None,
                        doc: None,
                        allowed_lints: vec![],
                        go_hints: vec![],
                    },
                )]),
                attributes: Attributes::default(),
            },
        }
    }

    #[test]
    fn full_generic_receiver_is_a_selector_method() {
        let definition = definition(method(&["T"], receiver(vec![Type::Parameter("T".into())])));

        assert!(!definition.is_ufcs_method("map"));
    }

    #[test]
    fn extra_method_generic_requires_ufcs() {
        let definition = definition(method(
            &["T", "U"],
            receiver(vec![Type::Parameter("T".into())]),
        ));

        assert!(definition.is_ufcs_method("map"));
    }

    #[test]
    fn specialized_receiver_requires_ufcs() {
        let definition = definition(method(&["T"], receiver(vec![Type::int()])));

        assert!(definition.is_ufcs_method("map"));
    }
}