{"record":{"id":"af3b84dfeeac2ebb","repo":"PRQL/prql","slug":"unexpected-found-this-is-probably-a-bad-type","errorCode":null,"errorMessage":"Unexpected `{found}` (this is probably a 'bad type' error)","messagePattern":"Unexpected `(.+?)` \\(this is probably a 'bad type' error\\)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"prqlc/prqlc/src/semantic/lowering.rs","lineNumber":977,"sourceCode":"\n            pl::ExprKind::Tuple(_) => {\n                return Err(\n                    Error::new_simple(\"table instance cannot be referenced directly\")\n                        .push_hint(\"column name might be missing?\")\n                        .with_span(span),\n                );\n            }\n\n            pl::ExprKind::Array(exprs) => rq::ExprKind::Array(\n                exprs\n                    .into_iter()\n                    .map(|x| self.lower_expr(x))\n                    .try_collect()?,\n            ),\n\n            pl::ExprKind::FuncCall(_) | pl::ExprKind::Func(_) | pl::ExprKind::TransformCall(_) => {\n                log::debug!(\"cannot lower {expr:?}\");\n                return Err(Error::new(Reason::Unexpected {\n                    found: format!(\"`{}`\", write_pl(expr.clone())),\n                })\n                .push_hint(\"this is probably a 'bad type' error (we are working on that)\")\n                .with_span(expr.span));\n            }\n\n            pl::ExprKind::Internal(_) => {\n                return Err(Error::new_assert(format!(\n                    \"Unresolved lowering: {}\",\n                    write_pl(expr)\n                )))\n            }\n        };\n\n        Ok(rq::Expr { kind, span })\n    }\n\n    fn lower_interpolations(","sourceCodeStart":959,"sourceCodeEnd":995,"githubUrl":"https://github.com/PRQL/prql/blob/e164e249b99485890036eb60f57c37520379b240/prqlc/prqlc/src/semantic/lowering.rs#L959-L995","documentation":"The lowering phase only handles expressions that the resolver has already type-checked and flattened into simple constructs. If it still encounters a `FuncCall`, `Func`, or `TransformCall`, it means a function or transform survived into lowering, which indicates a prior type error (the compiler says it is 'probably a bad type error').","triggerScenarios":"Calling a function in a position whose expected type does not invoke/lower it, e.g. a function used as a value `select my_func` (without call) or a transform like `filter` used as a value, or a user-defined function whose argument type inference failed.","commonSituations":"Forgetting to call a function (missing parentheses/arguments), passing a transform where a column is expected, or a type annotation mismatch that left the function unresolved.","solutions":["Check that functions are actually called with arguments, not referenced as values","Verify the argument types of your custom functions (a 'bad type' upstream likely caused this)","Look for transforms (`filter`, `select`, etc.) used outside pipeline position","Reformulate the expression so functions/transforms appear only in pipeline contexts"],"exampleFix":"// before\nselect my_func\n// after\nselect my_func col","handlingStrategy":"try-catch","validationCode":"// Ensure every function reference is invoked (has call args)\nfor (const fn of customFunctions) {\n  if (!query.includes(fn.name + \" \") && !query.includes(fn.name + \"(\")) {\n    console.warn(`function ${fn.name} may be used as a value`);\n  }\n}","typeGuard":"function isCalledFunction(node) {\n  return node.kind === \"func_call\" || node.kind === \"func\";\n}","tryCatchPattern":"try {\n  compile(query);\n} catch (e) {\n  if (e.message.includes(\"'bad type' error\")) {\n    console.error(\"Check function argument types; a function/transform leaked into value position:\", e.message);\n  } else { throw e; }\n}","preventionTips":["Always call functions with arguments; never reference them as values","Annotate custom function parameter types so inference fails earlier with better errors","Keep transforms (filter/select) only in pipeline position"],"tags":["prql","lowering","bad-type"],"backgroundTag":"type-mismatch","analyzedSha":"e164e249b99485890036eb60f57c37520379b240","analyzedAt":"2026-09-09T12:18:38.727Z","contentChangedAt":"2026-09-09T12:18:38.727Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}