Skip to content

Kind inference should suppress dependent 'unknown type' errors after earlier type-definition failures #2249

@johnynek

Description

@johnynek

The kind/shape solving pass can currently report misleading follow-on unknown type errors for local types that are not actually unknown, but only failed earlier in the same package.

Example from test_workspace/Bosatsu/Eval.bosatsu on the current branch:

11. type error
  in type Leaf unknown type Bosatsu/Lazy::Lazy in constructor LazyLeaf

12. type error
  in type Eval unknown type Leaf in constructor Pure

13. type error
  in type Stack unknown type Eval in constructor Last

That last message is misleading. Eval is not unknown; it was already seen and failed to compile because it depended on Leaf, which had already failed.

This looks like a regression in the newer alias-aware KindFormula.solveShapesAndKinds path. The older solveAll logic tracked a failed set and skipped solving later types whose dependsOn referenced previously failed local types, which avoided these misleading UnknownConst cascades.

A small repro should look like:

package Repro
export Bad, UsesBad

enum Bad:
  Bad(x: Missing)

enum UsesBad:
  UsesBad(x: Bad)

Expected behavior:

  • Report the original failure on Bad.
  • Do not later report Bad as an unknown type inside UsesBad.
  • Either suppress the dependent error entirely, or replace it with a diagnostic that says UsesBad depends on Bad, which had previous errors.

This is separate from export diagnostics. The root issue here is that kind/shape inference is treating previously-failed local items as if they were absent from the local environment, which creates noisy and misleading follow-on errors.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions