{"record":{"id":"6e5ab50a5f611fcb","repo":"lutzroeder/netron","slug":"unexpected-affine-expression-kind-this-kind","errorCode":null,"errorMessage":"Unexpected affine expression kind '${this.kind}'.","messagePattern":"Unexpected affine expression kind '(.+?)'\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"source/mlir.js","lineNumber":1422,"sourceCode":"    constructor(kind, lhs, rhs) {\n        super(kind);\n        this.lhs = lhs;\n        this.rhs = rhs;\n    }\n\n    isSymbolicOrConstant() {\n        return this.lhs.isSymbolicOrConstant() && this.rhs.isSymbolicOrConstant();\n    }\n\n    printAffineExprInternal(enclosingStrong) {\n        let op = '';\n        switch (this.kind) {\n            case _.AffineExprKind.Add: op = ' + '; break;\n            case _.AffineExprKind.Mul: op = ' * '; break;\n            case _.AffineExprKind.Mod: op = ' mod '; break;\n            case _.AffineExprKind.FloorDiv: op = ' floordiv '; break;\n            case _.AffineExprKind.CeilDiv: op = ' ceildiv '; break;\n            default: throw new Error(`Unexpected affine expression kind '${this.kind}'.`);\n        }\n        const isAdd = this.kind === _.AffineExprKind.Add;\n        const needsParens = enclosingStrong === true;\n        if (!isAdd) {\n            if (this.kind === _.AffineExprKind.Mul && this.rhs instanceof _.AffineConstantExpr && this.rhs.value === -1) {\n                const inner = `-${this.lhs.printAffineExprInternal(true)}`;\n                return needsParens ? `(${inner})` : inner;\n            }\n            const inner = `${this.lhs.printAffineExprInternal(true)}${op}${this.rhs.printAffineExprInternal(true)}`;\n            return needsParens ? `(${inner})` : inner;\n        }\n        if (this.rhs instanceof _.AffineBinaryOpExpr && this.rhs.kind === _.AffineExprKind.Mul &&\n            this.rhs.rhs instanceof _.AffineConstantExpr && this.rhs.rhs.value === -1) {\n            const lhsStr = this.lhs.printAffineExprInternal(false);\n            const rhsNeedsParens = this.rhs.lhs instanceof _.AffineBinaryOpExpr && this.rhs.lhs.kind === _.AffineExprKind.Add;\n            const rhsStr = this.rhs.lhs.printAffineExprInternal(rhsNeedsParens);\n            const inner = `${lhsStr} - ${rhsStr}`;\n            return needsParens ? `(${inner})` : inner;","sourceCodeStart":1404,"sourceCodeEnd":1440,"githubUrl":"https://github.com/lutzroeder/netron/blob/d8a543f5f847ef596aa58858d6adcf5d75545f7f/source/mlir.js#L1404-L1440","documentation":"Thrown while printing/serializing an MLIR affine expression whose 'kind' does not match any known AffineExprKind (Add, Mul, Mod, FloorDiv, CeilDiv). The printer switch falls through to the default case, meaning the expression object was constructed with an invalid or undefined kind value.","triggerScenarios":"Calling printAffineExprInternal (directly or via toString/print on an AffineExpr) on an expression whose kind is undefined or an out-of-range enum value, e.g. building AffineBinaryOpExpr without passing kind, or deserializing an affine map with a corrupt kind field.","commonSituations":"Constructing affine expressions manually for MLIR map parsing/printing, version skew between the bundled MLIR enum values and parsed input, or a half-initialized object where kind was never set.","solutions":["Inspect this.kind at the call site — it is likely undefined; ensure the AffineBinaryOpExpr constructor receives a valid _.AffineExprKind value.","Check that the affine map data being parsed was produced by a compatible MLIR dialect version.","Guard before printing: if (this.kind === undefined) fall back to raw operand printing or skip."],"exampleFix":"// before\nconst expr = new mlir.AffineBinaryOpExpr(undefined, lhs, rhs);\nexpr.printAffineExprInternal(); // throws\n\n// after\nconst expr = new mlir.AffineBinaryOpExpr(mlir.AffineExprKind.Add, lhs, rhs);\nexpr.printAffineExprInternal();","handlingStrategy":"validation","validationCode":"const validKinds = new Set(Object.values(mlir.AffineExprKind));\nif (!validKinds.has(expr.kind)) {\n    throw new Error(`Cannot print affine expression with kind=${expr.kind}`);\n}","typeGuard":"function isPrintableAffineExpr(e) {\n    const kinds = new Set(Object.values(mlir.AffineExprKind));\n    return e != null && kinds.has(e.kind);\n}","tryCatchPattern":"try { out = expr.printAffineExprInternal(); }\ncatch (e) { if (/Unexpected affine expression kind/.test(e.message)) out = '<invalid-affine-expr>'; else throw e; }","preventionTips":["Always construct AffineBinaryOpExpr with an explicit AffineExprKind constant.","Unit-test affine map printing against known-good strings.","Never deserialize enum kinds from untrusted numeric input without range checks."],"tags":["mlir","affine-expression","invalid-enum","printer"],"backgroundTag":"invalid-enum-value","analyzedSha":"d8a543f5f847ef596aa58858d6adcf5d75545f7f","analyzedAt":"2026-08-27T19:21:42.082Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}