Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions bin/cli-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,26 @@ export async function displaySourceContext(
const template = result.pass0.templates.get(filePath);
content = template?.raw.join("\n");
} else if (errorType === "generate" && result?.pass1) {
// For generator errors, use pass1 (parsed content before generation)
// For generator errors, use pass1 but map each parsed line back to its original raw source line
const template = result.pass1.templates.get(filePath);
content = template?.pass1.join("\n");
if (template) {
const errorLine = template.pass1[lineNumber - 1];
if (errorLine.codeReference.filePath !== filePath) {
console.error(` Original File: ${errorLine.codeReference.filePath}`);
}
if (errorLine.codeReference.filePath !== filePath || errorLine.codeReference.lineNumber !== lineNumber) {
console.error(` Original Line: ${errorLine.codeReference.lineNumber}`);
}

content = template.pass1
.map((pl) => {
const original = result.pass0?.templates.get(pl.codeReference.filePath)?.raw[
pl.codeReference.lineNumber - 1
];
return original !== undefined ? original : pl.line; // fallback to processed line text
})
.join("\n");
}
} else if (errorType === "build" && result?.pass2) {
// For build errors, use pass2 (generated content before build)
const template = result.pass2.templates.get(filePath);
Expand Down
26 changes: 17 additions & 9 deletions src/generator-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -448,16 +448,24 @@ function generateImpl(generatorState: GeneratorState, options: GenerateOptions)

for (const param of params) {
const pattern = createParamPattern(param);
if (
patterns.filter((p) => p.type === "param").some((p) => p.pattern.toString() === pattern.pattern.toString())
) {
throw new WgslTemplateGenerateError(
`Duplicate param: ${param} at line ${currentLine + 1}`,
"parameter-type-mismatch",
{ filePath: generatorState.filePath, lineNumber: currentLine + 1 }
);
// Allow duplicates if same (including same implied type), but error on type mismatch when types are specified.
const existing = patterns.find(
(p) => p.type === "param" && p.pattern.toString() === pattern.pattern.toString()
);
if (!existing) {
patterns.push(pattern);
} else {
const existingType = existing.paramType || "int";
const newType = pattern.paramType || "int";
if (existingType !== newType) {
throw new WgslTemplateGenerateError(
`Duplicate param with different type: ${param} at line ${currentLine + 1}`,
"parameter-type-mismatch",
{ filePath: generatorState.filePath, lineNumber: currentLine + 1 }
);
}
// otherwise silently ignore duplicate
}
patterns.push(pattern);
}
} else if (line.startsWith("#if ")) {
if (currentFunctionCall.length > 0) {
Expand Down
13 changes: 0 additions & 13 deletions test/testcases/generator-param-invalid-duplicate/test-config.json

This file was deleted.

This file was deleted.