mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-23 08:47:56 +01:00
Check that expr's don't have placeholder type
This commit is contained in:
1 parent
6ede44e474
commit
295cbbccae
1 file changed
+31
-22
+31
-22
@@ -657,33 +657,42 @@ func (c *Checker) checkAllTypeChecked(node *a.Node) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func nodeDebugString(tm *t.Map, n *a.Node) string {
|
||||||
|
switch n.Kind() {
|
||||||
|
case a.KConst:
|
||||||
|
return fmt.Sprintf("%s node %q", n.Kind(), n.AsConst().QID().Str(tm))
|
||||||
|
case a.KExpr:
|
||||||
|
return fmt.Sprintf("%s node %q", n.Kind(), n.AsExpr().Str(tm))
|
||||||
|
case a.KFunc:
|
||||||
|
return fmt.Sprintf("%s node %q", n.Kind(), n.AsFunc().QQID().Str(tm))
|
||||||
|
case a.KTypeExpr:
|
||||||
|
return fmt.Sprintf("%s node %q", n.Kind(), n.AsTypeExpr().Str(tm))
|
||||||
|
case a.KStatus:
|
||||||
|
return fmt.Sprintf("%s node %q", n.Kind(), n.AsStatus().QID().Str(tm))
|
||||||
|
case a.KStruct:
|
||||||
|
return fmt.Sprintf("%s node %q", n.Kind(), n.AsStruct().QID().Str(tm))
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("%s node", n.Kind())
|
||||||
|
}
|
||||||
|
|
||||||
func allTypeChecked(tm *t.Map, n *a.Node) error {
|
func allTypeChecked(tm *t.Map, n *a.Node) error {
|
||||||
return n.Walk(func(o *a.Node) error {
|
return n.Walk(func(o *a.Node) error {
|
||||||
typ := o.MType()
|
typ := o.MType()
|
||||||
if typ == nil {
|
if typ == nil {
|
||||||
switch o.Kind() {
|
return fmt.Errorf("check: internal error: unchecked %s", nodeDebugString(tm, o))
|
||||||
case a.KConst:
|
|
||||||
return fmt.Errorf("check: internal error: unchecked %s node %q",
|
|
||||||
o.Kind(), o.AsConst().QID().Str(tm))
|
|
||||||
case a.KExpr:
|
|
||||||
return fmt.Errorf("check: internal error: unchecked %s node %q",
|
|
||||||
o.Kind(), o.AsExpr().Str(tm))
|
|
||||||
case a.KFunc:
|
|
||||||
return fmt.Errorf("check: internal error: unchecked %s node %q",
|
|
||||||
o.Kind(), o.AsFunc().QQID().Str(tm))
|
|
||||||
case a.KTypeExpr:
|
|
||||||
return fmt.Errorf("check: internal error: unchecked %s node %q",
|
|
||||||
o.Kind(), o.AsTypeExpr().Str(tm))
|
|
||||||
case a.KStatus:
|
|
||||||
return fmt.Errorf("check: internal error: unchecked %s node %q",
|
|
||||||
o.Kind(), o.AsStatus().QID().Str(tm))
|
|
||||||
case a.KStruct:
|
|
||||||
return fmt.Errorf("check: internal error: unchecked %s node %q",
|
|
||||||
o.Kind(), o.AsStruct().QID().Str(tm))
|
|
||||||
}
|
|
||||||
return fmt.Errorf("check: internal error: unchecked %s node", o.Kind())
|
|
||||||
}
|
}
|
||||||
if o.Kind() == a.KExpr {
|
|
||||||
|
switch o.Kind() {
|
||||||
|
default:
|
||||||
|
if typ != typeExprPlaceholder {
|
||||||
|
return fmt.Errorf("check: internal error: %s does not have placeholder type", nodeDebugString(tm, o))
|
||||||
|
}
|
||||||
|
|
||||||
|
case a.KExpr:
|
||||||
|
if typ == typeExprPlaceholder {
|
||||||
|
return fmt.Errorf("check: internal error: %s has placeholder type", nodeDebugString(tm, o))
|
||||||
|
}
|
||||||
|
|
||||||
o := o.AsExpr()
|
o := o.AsExpr()
|
||||||
if typ.IsIdeal() && o.ConstValue() == nil {
|
if typ.IsIdeal() && o.ConstValue() == nil {
|
||||||
return fmt.Errorf("check: internal error: expression %q has ideal number type "+
|
return fmt.Errorf("check: internal error: expression %q has ideal number type "+
|
||||||
|
|||||||
Reference in new issue
Block a user