Closed pobearm closed 1 year ago
Error occurs at parse.go#L154
indicating that the type Copygen Interface
is not being detected in the setup.go
file within the current directory (after it has been added to the keep). This means that the interface not in the go/types
of the packages.Load
function at parse.go#L143
. There is not an explicit check on whether it is detected within the Keep using the ast
loader.
Please show your file structure for this demo alongside the command used to run it @pobearm.
You can ignore this message unless you plan to fix this issue.
https://github.com/switchupcb/copygen/blob/19e910b3a024f6b4b1ef663859b28487b727f4dc/cli/config/yml.go#L28 gets the file path from the file location of the .yml
file. https://github.com/switchupcb/copygen/blob/19e910b3a024f6b4b1ef663859b28487b727f4dc/cli/config/yml.go#L34 uses filepath.Dir
which gets all parts but the last element of the path. It's expected that the user provides a .yml
file as the loader path flag such that filepath.Dir
is equivalent to the directory containing the loader. Such that filepath.Join(loaderDir, ./setup.go)
resolves to loaderDir/setup.go
.
The package does not fail to load.
assertCopygenInterface
at https://github.com/switchupcb/copygen/blob/ea03ecfaa3468b66e34a9d41c908a91fc7f28044/cli/parser/ast.go checks for the interface via ast
.
Hypothesis
All tested examples generate the output file in a separate directory from the setup file. Such that placing the setup file and output file in the same directory may result in undefined behavior. Otherwise, user is using outdated files (unsaved) or a wrong configuration that doesn't error (bug).
placing the setup file and output file in the same directory may result in undefined behavior.
This error occurs when the user uses multiple files in the same directory as the setup file, and the setup file isn't the first file. This happened because only the first file's AST in a directory was checked for the type Copygen interface
.
parser.ParseFile
parses a single file, which will always parse the correct (setup) file to receive the AST of the setup file. However, an error has been added to specify when the Copygen interface
hasn't been found in the AST.
The packages loaded from packages.Load
of the setup file generates a new AST. So this AST must be checked for a new Copygen interface
because it matches to that loader's go/types
. Unlike parseFile
, there is no guarantee that a single file is present nor that the setup file is the first. So each file is checked until the Copygen interface
is found.
Use
go install github.com/switchupcb/copygen@main
to update to a version with this fix.
Please provide the following information.
Setup
YML
Go
Output
Error
Generation
Environment
Operating System: windows 10 Copygen Version: 0.4.0 Golang Version : 1.19.4