Skip to content

C#: base types and type references resolve to enum members (and properties) of the same name #3795

Closed

Description

@ThatAblaze

Since enum members (case_of) and properties (#3006) became nodes, they are candidates when a
type name is resolved, and they win. The worst case is inheritance: a class loses its subclasses
to an enum member.

Repro A: inheritance, one file. Effects.cs:

namespace Demo
{
    public enum EffectKind { Tween, Follow }
    public abstract class Follow { }
    public sealed class FollowFloat : Follow { }
}

Actual: effects_demo_followfloat --inherits--> effects_demo_effectkind_follow, and no
inherits edge reaches the class effects_demo_follow.
Expected: effects_demo_followfloat --inherits--> effects_demo_follow.

Placement decides it. With Follow in its own file and the enum still beside FollowFloat, the
enum member still wins. With the enum moved to another file (class and subclass together, or all
three files separate), the class is chosen correctly. So a same-file enum member outranks a class
of the same name declared anywhere. Nesting everything in an outer class, making the types
generic (Follow<T> / FollowFloat : Follow<float>), or declaring the enum after the classes
changes nothing. Without the enum, the class is found.

Repro B: external types, across files. When the name is not a declared type at all, an enum
member or property in another file is used as the target:

Kinds.cs

namespace Demo
{
    public enum Channel { Vector2 }
}

Node.cs

namespace Demo
{
    public class Node
    {
        public System.Type Type { get; set; }
    }
}

Mover.cs

using System;
using UnityEngine;

namespace Demo
{
    public class Mover
    {
        public void Move(Vector2 delta) { }
        public string Describe(Type t) => t.Name;
    }
}

Actual:

mover_demo_mover_move     --references--> kinds_demo_channel_vector2   (parameter_type)
mover_demo_mover_describe --references--> node_demo_node_type          (parameter_type)

Expected: an external-type placeholder (what you get when no such member exists) or no edge;
Move takes UnityEngine.Vector2 and Describe takes System.Type.

An enum member or a property can never be the target of an inherits / implements edge or of
a parameter_type / return_type / field / generic_arg reference, so excluding them from
type-name resolution (both the file-local lookup and the global fallback) should fix both repros.

Impact on a real ~120-file Unity codebase: every concrete effect class (TweenFloat,
FollowFloat, WaitFloat, ...) inherited an enum member instead of its abstract base, because
the effect-kind enum lives in the same file as the classes; and 183 UnityEngine.Vector2
references landed on one enum member, making it the graph's fourth-largest hub and skewing the
report's god nodes and communities. About 480 misbound edges in total.

Activity

  1. safishamsi commented on Sep 25, 2026

    @safishamsi
    Member
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions