Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't prevent going to next stage when a warning is elevated to an error #2983

Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
# Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking
changeKind: fix
packages:
- "@typespec/compiler"
---

Warnings converted to error with `warn-as-error` do not prevent compilation from moving to the next stage like regular warnings
9 changes: 7 additions & 2 deletions packages/compiler/src/core/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ export async function compile(
const loadedLibraries = new Map<string, TypeSpecLibraryReference>();
const sourceFileLocationContexts = new WeakMap<SourceFile, LocationContext>();
let error = false;
let continueToNextStage = true;

const logger = createLogger({ sink: host.logSink });
const tracer = createTracer(logger, { filter: options.trace });
Expand Down Expand Up @@ -383,7 +384,7 @@ export async function compile(
program.checker = createChecker(program);
program.checker.checkProgram();

if (program.hasError()) {
if (!continueToNextStage) {
return program;
}
// onValidate stage
Expand All @@ -392,7 +393,7 @@ export async function compile(
validateRequiredImports();

await validateLoadedLibraries();
if (program.hasError()) {
if (!continueToNextStage) {
return program;
}

Expand Down Expand Up @@ -1049,6 +1050,10 @@ export async function compile(
return;
}

if (diagnostic.severity === "error") {
continueToNextStage = false;
}

if (diagnostic.severity === "warning" && diagnostic.target !== NoTarget) {
mutate(diagnostic).codefixes ??= [];
mutate(diagnostic.codefixes).push(createSuppressCodeFix(diagnostic.target, diagnostic.code));
Expand Down
Loading