rust icon indicating copy to clipboard operation
rust copied to clipboard

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

Open nikomatsakis opened this issue 14 years ago • 8 comments

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

nikomatsakis avatar Jul 24 '12 23:07 nikomatsakis

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 :).

pnkfelix avatar Apr 25 '13 14:04 pnkfelix

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

pcwalton avatar May 16 '13 23:05 pcwalton

accepted for production-ready milestone

graydon avatar Jun 06 '13 17:06 graydon

appears to be properly classified

bblum avatar Aug 16 '13 23:08 bblum

Accepting for P-high.

pnkfelix avatar Jan 16 '14 18:01 pnkfelix

Tagging as mentorship bug, with @nikomatsakis as mentor

pnkfelix avatar Jan 16 '14 18:01 pnkfelix

This code triggers the same infinite recursion in type_structurally_contains:

enum E { A, B(Bad) }
struct Bad { x: Bad }

isabelmu avatar Jan 19 '14 14:01 isabelmu

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.

isabelmu avatar Jan 27 '14 05:01 isabelmu