toeverything/AFFiNE · error · BlockSuiteError

DatabaseBlockError

DatabaseBlockError

Error message

unexpected type unify, type var reference

What it means

TypeVarReference is a placeholder node representing an unbound type variable in the data-view logical type system. Its unify() is intentionally a hard failure: unifying against an unresolved reference is a logic error because the reference should have been substituted via subst() first.

Source

Thrown at blocksuite/affine/data-view/src/core/logical/type-variable.ts:36

}

export class TypeVarReferenceInstance<
  Name extends string = string,
> implements TypeInstance {
  readonly _validate = unknownSchema;

  readonly _valueType = undefined as unknown;

  readonly name = '__TypeVarReference';

  constructor(readonly varName: Name) {}

  subst(ctx: TypeVarContext): void | TypeInstance {
    return ctx[this.varName]?.type;
  }

  unify(_ctx: TypeVarContext, _type: TypeInstance, _unify: Unify): boolean {
    throw new BlockSuiteError(
      ErrorCode.DatabaseBlockError,
      'unexpected type unify, type var reference'
    );
  }

  valueValidate(_value: unknown): _value is unknown {
    return true;
  }
}

export const tv = {
  typeVarDefine: {
    create: <
      Name extends string = string,
      Type extends TypeInstance = TypeInstance,
    >(
      name: Name,
      typeConstraint?: Type

View on GitHub (pinned to 26c515e050)

Solutions

  1. Ensure subst(ctx) is applied to bind the type variable before unify() is called.
  2. Avoid constructing type expressions with bare references where unification is expected.
  3. Treat hitting this throw as an internal-invariant bug to report upstream.
Defensive patterns

Strategy: try-catch

Try / catch

try { typeA.unify(ctx, typeB, unifyFn); } catch (e) { if (e instanceof BlockSuiteError && e.code === ErrorCode.DatabaseBlockError) { /* report internal invariant */ } }

Prevention

When it happens

Trigger: Calling unify() on a TypeInstance that is still a TypeVarReference, i.e. before the type-variable context has substituted it with a concrete type.

Common situations: A bug in type inference ordering where unify runs before substitution; building type expressions that leave a `tv.reference(...)` node in a position where unification is attempted.

Related errors


AI-assisted analysis of toeverything/AFFiNE@26c515e050 (2026-08-12). Data as JSON: /api/errors/93d228ef60f15f92. Report an issue: GitHub.