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

refactor: export BoundTypeError with Fset and Pos fields #472

Merged
merged 1 commit into from
Mar 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion builtin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,7 @@ func TestTypeEx(t *testing.T) {
typ.Underlying()
}()
}
bte := &boundTypeError{tyInt, TyByte}
bte := &BoundTypeError{Fset: pkg.cb.fset, a: tyInt, b: TyByte}
if bte.Error() != "boundType int => byte failed" {
t.Fatal("boundTypeError:", bte)
}
Expand Down
14 changes: 10 additions & 4 deletions template.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,21 @@
return t
}

type boundTypeError struct {
type BoundTypeError struct {
Fset dbgPositioner
Pos token.Pos
a, b types.Type
}

func (p *boundTypeError) Error() string {
func (p *BoundTypeError) Error() string {
return fmt.Sprintf("boundType %v => %v failed", p.a, p.b)
}

func boundType(pkg *Package, arg, param types.Type, parg *internal.Elem) error {
var pos token.Pos
if parg != nil && parg.Src != nil {
pos = parg.Src.Pos()
}
switch p := param.(type) {
case *unboundFuncParam: // template function param
if p.tBound == nil {
Expand All @@ -116,7 +122,7 @@
p.boundTo(pkg, arg, parg)
} else if !AssignableConv(pkg, getElemTypeIf(arg, parg), p.tBound, parg) {
if !(isUntyped(pkg, p.tBound) && AssignableConv(pkg, p.tBound, arg, p.parg)) {
return &boundTypeError{a: arg, b: p.tBound}
return &BoundTypeError{Fset: pkg.cb.fset, Pos: pos, a: arg, b: p.tBound}
}
p.tBound = arg
}
Expand All @@ -137,7 +143,7 @@
case *types.Map:
if t, ok := arg.(*types.Map); ok {
if err1 := boundType(pkg, t.Key(), param.Key(), nil); err1 != nil { // TODO: expr = nil
return &boundTypeError{a: t.Key(), b: param.Key()}
return &BoundTypeError{Fset: pkg.cb.fset, Pos: pos, a: t.Key(), b: param.Key()}

Check warning on line 146 in template.go

View check run for this annotation

Codecov / codecov/patch

template.go#L146

Added line #L146 was not covered by tests
}
return boundType(pkg, t.Elem(), param.Elem(), nil) // TODO: expr = nil
}
Expand Down
Loading