{"record":{"id":"93d228ef60f15f92","repo":"toeverything/AFFiNE","slug":"databaseblockerror-93d228","errorCode":"DatabaseBlockError","errorMessage":"unexpected type unify, type var reference","messagePattern":"unexpected type unify, type var reference","errorType":"exception","errorClass":"BlockSuiteError","httpStatus":null,"severity":"error","filePath":"blocksuite/affine/data-view/src/core/logical/type-variable.ts","lineNumber":36,"sourceCode":"}\n\nexport class TypeVarReferenceInstance<\n  Name extends string = string,\n> implements TypeInstance {\n  readonly _validate = unknownSchema;\n\n  readonly _valueType = undefined as unknown;\n\n  readonly name = '__TypeVarReference';\n\n  constructor(readonly varName: Name) {}\n\n  subst(ctx: TypeVarContext): void | TypeInstance {\n    return ctx[this.varName]?.type;\n  }\n\n  unify(_ctx: TypeVarContext, _type: TypeInstance, _unify: Unify): boolean {\n    throw new BlockSuiteError(\n      ErrorCode.DatabaseBlockError,\n      'unexpected type unify, type var reference'\n    );\n  }\n\n  valueValidate(_value: unknown): _value is unknown {\n    return true;\n  }\n}\n\nexport const tv = {\n  typeVarDefine: {\n    create: <\n      Name extends string = string,\n      Type extends TypeInstance = TypeInstance,\n    >(\n      name: Name,\n      typeConstraint?: Type","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/toeverything/AFFiNE/blob/26c515e050211269e911f7d9cfe162a26c83ed98/blocksuite/affine/data-view/src/core/logical/type-variable.ts#L18-L54","documentation":"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.","triggerScenarios":"Calling unify() on a TypeInstance that is still a TypeVarReference, i.e. before the type-variable context has substituted it with a concrete type.","commonSituations":"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.","solutions":["Ensure subst(ctx) is applied to bind the type variable before unify() is called.","Avoid constructing type expressions with bare references where unification is expected.","Treat hitting this throw as an internal-invariant bug to report upstream."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { typeA.unify(ctx, typeB, unifyFn); } catch (e) { if (e instanceof BlockSuiteError && e.code === ErrorCode.DatabaseBlockError) { /* report internal invariant */ } }","preventionTips":["Apply subst(ctx) to bind type variables before unification","Report occurrences — this is an internal-invariant violation"],"tags":["data-view","type-system","logical","internal"],"backgroundTag":null,"analyzedSha":"26c515e050211269e911f7d9cfe162a26c83ed98","analyzedAt":"2026-08-12T13:15:16.447Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}