shader: Bug fix: selector is not available on a blank identifier

This commit is contained in:
Hajime Hoshi 2020-09-14 03:41:25 +09:00
parent e1d8629189
commit ded223ead0
2 changed files with 14 additions and 4 deletions

View File

@ -437,7 +437,7 @@ func (cs *compileState) parseExpr(block *block, expr ast.Expr, markLocalVariable
return cs.parseExpr(block, e.X, markLocalVariableUsed)
case *ast.SelectorExpr:
exprs, _, stmts, ok := cs.parseExpr(block, e.X, markLocalVariableUsed)
exprs, _, stmts, ok := cs.parseExpr(block, e.X, true)
if !ok {
return nil, nil, nil, false
}

View File

@ -572,8 +572,8 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
x.x = 1
return vec4(0)
}
`)); err == nil {
t.Errorf("error must be non-nil but was nil")
`)); err != nil {
t.Error(err)
}
// Increment statement treats a variable 'used'.
@ -590,7 +590,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
}
}
func TestShaderBlankRhs(t *testing.T) {
func TestShaderBlankLhs(t *testing.T) {
if _, err := NewShader([]byte(`package main
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
@ -652,6 +652,16 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
_ += 1
return vec4(0)
}
`)); err == nil {
t.Errorf("error must be non-nil but was nil")
}
if _, err := NewShader([]byte(`package main
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
_.x = 1
return vec4(0)
}
`)); err == nil {
t.Errorf("error must be non-nil but was nil")
}