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

Bicep file referencing an exported type used in the outputs of the file containing the custom type can crash compiler #15898

Closed
joetossell opened this issue Dec 17, 2024 · 0 comments · Fixed by #15899
Assignees
Labels
bug Something isn't working Needs: Triage 🔍
Milestone

Comments

@joetossell
Copy link

joetossell commented Dec 17, 2024

Bicep version
Bicep CLI version 0.32.4 (b326faa)

Describe the bug
Scenario:

  • A type is exported from someType.bicep and is explicitly imported into consumer.bicep
  • There is an output in someType.bicep that uses the exported type
  • The output has the same name as the exported type

When compiled using az bicep build -f .\consumer.bicep the compiler throws an unhandled exception:

Unhandled exception. System.InvalidOperationException: Sequence contains more than one element
   at System.Linq.ThrowHelper.ThrowMoreThanOneElementException()
   at System.Linq.Enumerable.TryGetSingle[TSource](IEnumerable`1, Boolean& )
   at System.Linq.Enumerable.Single[TSource](IEnumerable`1)
   at Bicep.Core.Emit.CompileTimeImports.ImportClosureInfo.FindSymbolNamed(String nameOfSymbolSought, SemanticModel model)
   at Bicep.Core.Emit.CompileTimeImports.ImportClosureInfo.CalculateImportClosure(SemanticModel model, IntraTemplateSymbolicReferenceFactory referenceFactory)
   at Bicep.Core.Emit.CompileTimeImports.ImportClosureInfo.Calculate(SemanticModel model)
   at Bicep.Core.Emit.EmitterContext.<>c__DisplayClass1_0.<.ctor>b__0()
   at System.Lazy`1.PublicationOnlyViaFactory(LazyHelper)
   at System.Lazy`1.CreateValue()
   at System.Lazy`1.get_Value()
   at Bicep.Core.Emit.EmitterContext.get_ImportClosureInfo()
   at Bicep.Core.Emit.TemplateWriter.GenerateTemplateWithoutHash(PositionTrackingJsonTextWriter jsonWriter)
   at Bicep.Core.Emit.TemplateWriter.Write(SourceAwareJsonTextWriter writer)
   at Bicep.Core.Emit.TemplateEmitter.<>c__DisplayClass8_0.<Emit>b__0()
   at Bicep.Core.Emit.TemplateEmitter.EmitOrFail(Func`1 write)
   at Bicep.Core.Emit.TemplateEmitter.Emit(TextWriter textWriter)
   at Bicep.Core.Emit.CompilationEmitter.Template(SemanticModel model)
   at Bicep.Core.Emit.CompilationEmitter.Template()
   at Bicep.Cli.Services.OutputWriter.TemplateToFile(Compilation compilation, Uri outputUri)
   at Bicep.Cli.Commands.BuildCommand.RunAsync(BuildArguments args)
   at Bicep.Cli.Program.RunAsync(String[] args, CancellationToken cancellationToken)
   at Bicep.Cli.Program.<>c__DisplayClass3_0.<<Main>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at Bicep.Cli.Program.RunWithCancellationAsync(Func`2 runFunc)
   at Bicep.Cli.Program.Main(String[] args)
   at Bicep.Cli.Program.<Main>(String[] args)

To Reproduce

someType.bicep

@export()
type someType = {}

output someType someType = {}
// output st someType = {} // this works!

consumer.bicep

import {someType} from 'someType.bicep'

run

az bicep build -f consumer.bicep

Additional context

For anyone else facing this error there are a number of options:

  • Use import * as st from 'someType.bicep'
  • Ensure the name of the output does not match the name of the type e.g. output st someType = {}

I imagine the second option is best advised

@github-project-automation github-project-automation bot moved this to Todo in Bicep Dec 17, 2024
@jeskew jeskew added the bug Something isn't working label Dec 17, 2024
@jeskew jeskew added this to the v0.33 milestone Dec 17, 2024
@jeskew jeskew self-assigned this Dec 17, 2024
@jeskew jeskew closed this as completed in 77f4bf4 Dec 18, 2024
@github-project-automation github-project-automation bot moved this from Todo to Done in Bicep Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Needs: Triage 🔍
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants