From 182b05e73b59a5aefe397740094a74526b99c070 Mon Sep 17 00:00:00 2001 From: Anthony Martin <38542602+anthony-c-martin@users.noreply.github.com> Date: Tue, 5 Mar 2024 09:23:12 -0500 Subject: [PATCH] Fix for issue 13531 (#13532) Closes #13531 ###### Microsoft Reviewers: [Open in CodeFlow](https://microsoft.github.io/open-pr/?codeflow=https://github.com/Azure/bicep/pull/13532) --- .../ScenarioTests.cs | 21 +++++++++++++++++++ .../Emit/EmitLimitationCalculator.cs | 14 ++++++------- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/Bicep.Core.IntegrationTests/ScenarioTests.cs b/src/Bicep.Core.IntegrationTests/ScenarioTests.cs index c1da621a361..30bc0192f1a 100644 --- a/src/Bicep.Core.IntegrationTests/ScenarioTests.cs +++ b/src/Bicep.Core.IntegrationTests/ScenarioTests.cs @@ -5622,6 +5622,27 @@ public void Test_Issue12908() }); } + // https://github.com/Azure/bicep/issues/13531 + [TestMethod] + public void Test_Issue13531() + { + var result = CompilationHelper.CompileParams( + ("parameters.bicepparam", """ +using 'main.bicep' + +param location = location +"""), + ("main.bicep", """ +#disable-next-line no-unused-params +param location string +""")); + + result.Should().HaveDiagnostics(new[] + { + ("BCP079", DiagnosticLevel.Error, """This expression is referencing its own declaration, which is not allowed."""), + }); + } + [TestMethod] public void Functions_can_be_imported_in_bicepparam_files() { diff --git a/src/Bicep.Core/Emit/EmitLimitationCalculator.cs b/src/Bicep.Core/Emit/EmitLimitationCalculator.cs index 6acf40f6a2a..1ca90630f75 100644 --- a/src/Bicep.Core/Emit/EmitLimitationCalculator.cs +++ b/src/Bicep.Core/Emit/EmitLimitationCalculator.cs @@ -513,6 +513,13 @@ private static void BlockCyclicAggregateTypeReferences(SemanticModel model, IDia foreach (var symbol in GetTopologicallySortedSymbols(referencesInValues)) { + if (symbol.Type is ErrorType) + { + // no point evaluating if we're already reporting an error + erroredSymbols.Add(symbol); + continue; + } + var referencedValueHasError = false; foreach (var referenced in referencesInValues[symbol]) { @@ -547,13 +554,6 @@ private static void BlockCyclicAggregateTypeReferences(SemanticModel model, IDia continue; } - if (parameter.Type is ErrorType) - { - // no point evaluating if we're already reporting an error - erroredSymbols.Add(parameter); - continue; - } - // We may emit duplicate errors here - type checking will also execute some ARM functions and generate errors // This is something we should improve before the first release. var result = evaluator.EvaluateParameter(parameter);