Skip to content

representable check fails if an enum references another enum that is cyclic #3008

Closed

Description

@nikomatsakis

Here is a test case:

// Compiler fails here because it starts to check foo which references
// bar which is cyclic.
enum foo { foo(bar) }
enum bar { bar_none, bar_some(bar) }

// As before, but with order reversed, so that should we happen to
// start checking from end of file forward, we'd still have the same
// problem.
enum bar1 { bar1_none, bar1_some(bar1) }
enum foo1 { foo1(bar1) }

fn main() {}

I think the right approach is to replace ty_structurally_contains() with something like walk_interior_tys(). then we have to keeep a stack of def-ids and when we enter a new nominal type check that we do not already have it on the stack. i started this then realized it was a big distraction from what I'm trying to do, so filing a bug instead. Marking as A-typesystem as this check is performed in middle/typeck/check.rs

Activity

  1. pnkfelix commented on Apr 25, 2013

    @pnkfelix
    Contributor

    Just to make this concrete: both of the cases that Niko describes yield ICE's. The first (the foo and bar items) yields an ICE with no useful error information. The second (bar1 and foo1) yields an error describing the illegal recursive enum type (followed by an ICE :).

  2. pcwalton commented on May 16, 2013

    @pcwalton
    Contributor

    I don't believe this is backwards incompatible, renominating.

  3. graydon commented on Jun 6, 2013

    @graydon
    Contributor

    accepted for production-ready milestone

  4. bblum commented on Aug 16, 2013

    @bblum
    Contributor

    appears to be properly classified

  5. pnkfelix commented on Jan 16, 2014

    @pnkfelix
    Contributor

    Accepting for P-high.

  6. pnkfelix commented on Jan 16, 2014

    @pnkfelix
    Contributor

    Tagging as mentorship bug, with @nikomatsakis as mentor

  7. isabelmu commented on Jan 19, 2014

    @isabelmu
    Contributor

    This code triggers the same infinite recursion in type_structurally_contains:

    enum E { A, B(Bad) }
    struct Bad { x: Bad }
  8. isabelmu commented on Jan 27, 2014

    @isabelmu
    Contributor

    I have a fix for this written, in case anyone is wondering whether to start working on it. I'll submit a pull request soon.

  9. added a commit that references this issue on Sep 28, 2023
  10. added a commit that references this issue on Aug 21, 2026
    aff82cf
  11. added a commit that references this issue on Sep 7, 2026
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

    A-type-systemArea: Type systemE-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.P-mediumMedium priority

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions