Skip to content

Conversation

@phihos
Copy link

@phihos phihos commented Dec 12, 2025

The emitter incorrectly used filepath.Ext() to distinguish template imports from native package imports. This caused imports without file extensions to be silently skipped, resulting in:

panic: scriggo: internal error: none of the previous conditions
matched identifier

The correct check is node.Tree != nil, which indicates a template import (parsed AST exists) vs node.Tree == nil for native package imports. This matches the logic used in the type checker.

Changes:

  • emitter_statements.go: Replace filepath.Ext check with node.Tree check
  • fstest/files.go: Add FormatFiles type for testing extension-less imports
  • multi_file_template_test.go: Add tests for extension-less macro/variable imports

The emitter incorrectly used filepath.Ext() to distinguish template
imports from native package imports. This caused imports without file
extensions to be silently skipped, resulting in:

  panic: scriggo: internal error: none of the previous conditions
         matched identifier <MacroName>

The correct check is node.Tree != nil, which indicates a template import
(parsed AST exists) vs node.Tree == nil for native package imports.
This matches the logic used in the type checker.

Changes:
- emitter_statements.go: Replace filepath.Ext check with node.Tree check
- fstest/files.go: Add FormatFiles type for testing extension-less imports
- multi_file_template_test.go: Add tests for extension-less macro/variable imports
Copy link
Member

@gazerro gazerro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this! I have a few comments below.


// Tests for extension-less imports using FormatFiles (FormatFS interface)
"import with 'for' - macro without file extension": {
sources: fstest.FormatFiles{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not necessary to introduce fastest.FormatFiles, since files without an extension already default to the Text format. I'd recommend restoring internal/fstest/files.go to its previous state.

expectedOut: "hello, world!",
},

// Tests for extension-less imports using FormatFiles (FormatFS interface)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would remove this comment, as the test name already documents the behavior.

pkg := node.Tree.Nodes[0].(*ast.Package)
funcs, vars, inits := em.emitPackage(pkg, false, node.Tree.Path)

// If importing specific identifiers with "for" clause, filter to only those.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of this change? It's not documented in the commit message, and the issue seems to be fixed even without it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants