Skip to content

Support generic struct and proto methods through monomorphization #435

Closed

Description

@LunaStev

Summary

The generic rewriting pass currently rejects methods with generic parameters inside structs and proto implementations. This leaves an intentional frontend gap even when the surrounding type can already be monomorphized.

Related issue

Relevant code

  • front/parser/src/generics.rs
  • generic environment and call-site resolution
  • typed HIR validation

Scope

Define and implement generic method instantiation for struct methods and proto implementation methods. Method-level type parameters must coexist predictably with receiver or enclosing-type parameters.

Acceptance criteria

  • Generic struct methods can be declared and called.
  • Generic proto implementation methods follow the same substitution rules.
  • Enclosing and method-level type parameters cannot collide silently.
  • Call-site inference and explicit generic arguments have documented behavior.
  • Equivalent instantiations are deduplicated.
  • Recursive or cyclic instantiation produces a diagnostic instead of unbounded rewriting.
  • Typed HIR retains fully resolved method signatures.
  • Positive and negative frontend fixtures cover nested generic types, ambiguity, and constraint failures.

Activity

  1. added
    enhancement
    help wanted
    feature request
    needs testing
    on Aug 29, 2026
  2. LunaStev commented on Sep 23, 2026

    @LunaStev
    MemberAuthor

    Verified against canonical master 509a1e4 and reran the existing coverage while preparing #701. front/parser/src/methods.rs describes explicit arguments, inference and enclosing-type substitution. All six generic_methods tests and generic_methods_and_nested_method_receivers_execute_once pass, covering struct/proto methods, deduplication, collisions, invalid arguments, bounded recursion and nested receivers. The implementation already satisfies this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementfeature requesthelp wantedneeds testing

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions