Skip to content

Commit

Permalink
Merge pull request #1799 from xushiwei/q
Browse files Browse the repository at this point in the history
TestErrStringLit
  • Loading branch information
xushiwei committed Mar 8, 2024
2 parents 62897ea + a850ff2 commit 89f4bb0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
6 changes: 6 additions & 0 deletions cl/error_msg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,12 @@ func (p *[]byte) foo() {
`)
}

func TestErrStringLit(t *testing.T) {
codeErrorTest(t, `bar.gop:2:9: [].string undefined (type []interface{} has no field or method string)`, `
echo "${[]}"
`)
}

func TestErrStructLit(t *testing.T) {
codeErrorTest(t,
`bar.gop:3:39: too many values in struct{x int; y string}{...}`, `
Expand Down
7 changes: 6 additions & 1 deletion cl/expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,12 @@ func compileStringLitEx(ctx *blockCtx, cb *gogen.CodeBuilder, lit *ast.BasicLit)
compileExpr(ctx, v, flags)
t := cb.Get(-1).Type
if t.Underlying() != types.Typ[types.String] {
cb.Member("string", gogen.MemberFlagAutoProperty)
if _, err := cb.Member("string", gogen.MemberFlagAutoProperty); err != nil {
if e, ok := err.(*gogen.CodeError); ok {
err = ctx.newCodeErrorf(v.Pos(), "%s.string%s", ctx.LoadExpr(v), e.Msg)
}
ctx.handleErr(err)
}
}
pos = v.End()
default:
Expand Down

0 comments on commit 89f4bb0

Please sign in to comment.