wails/v3/internal/generator/collect/void.go
Fabio Massaioli 04d99e376c
[v3] Fix global state in Collector.IsVoidAlias predicate (#4941)
* Accept obscure update to package-lock.json

* Make global state local in Collector.IsVoidAlias predicate

* Add protection against potential nil dereference

* Update test data

* Fix typo in doc comment

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* Update UNRELEASED_CHANGELOG.md

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
2026-02-02 09:44:56 +00:00

28 lines
768 B
Go

package collect
import (
"go/types"
)
// IsVoidAlias returns true when the given type or object is the application.Void named type that stands in for the void TS type.
func (collector *Collector) IsVoidAlias(typOrObj any) bool {
var obj types.Object
switch to := typOrObj.(type) {
case types.Object:
obj = to
case interface{ Obj() *types.TypeName }:
obj = to.Obj()
default:
return false
}
if vt := collector.appVoidType.Load(); vt != nil && obj == vt {
return true
} else if vt == nil && obj.Name() == "Void" && obj.Pkg() != nil && obj.Pkg().Path() == collector.systemPaths.ApplicationPackage { // Check name before package to fail fast
// Cache void alias for faster checking
collector.appVoidType.Store(obj)
return true
}
return false
}