Skip to content

Commit

Permalink
Merge pull request #308 from xushiwei/refactor
Browse files Browse the repository at this point in the history
MatchError.Message
  • Loading branch information
xushiwei authored Nov 2, 2023
2 parents 7ebd369 + 6425151 commit 424983d
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -1164,20 +1164,22 @@ func strval(at interface{}) string {
}
}

func (p *MatchError) Error() string {
at := token.NoPos
func (p *MatchError) Message(fileLine string) string {
if p.fstmt {
return fmt.Sprintf(
"%scannot use %v value as type %v in %s", fileLine, p.Arg, p.Param, strval(p.At))
}
src := ""
if p.Src != nil {
at = p.Src.Pos()
src = p.intr.LoadExpr(p.Src)
}
pos := p.Fset.Position(at)
if p.fstmt {
return fmt.Sprintf(
"%v: cannot use %v value as type %v in %s", pos, p.Arg, p.Param, strval(p.At))
}
return fmt.Sprintf(
"%v: cannot use %s (type %v) as type %v in %s", pos, src, p.Arg, p.Param, strval(p.At))
"%scannot use %s (type %v) as type %v in %s", fileLine, src, p.Arg, p.Param, strval(p.At))
}

func (p *MatchError) Error() string {
pos := p.Fset.Position(getSrcPos(p.Src))
return p.Message(pos.String() + ": ")
}

// TODO: use matchType to all assignable check
Expand Down

0 comments on commit 424983d

Please sign in to comment.