Add a TypeExpr type expression

This commit is contained in:
Nigel Tao committed 2018-07-07 21:57:15 +10:00
1 parent 295cbbccae
commit 731ca8841b
5 files changed
+39 -29

No files matched your search

+12 -8
View File
@@ -682,17 +682,21 @@ func allTypeChecked(tm *t.Map, n *a.Node) error {
return fmt.Errorf("check: internal error: unchecked %s", nodeDebugString(tm, o))
}
typOK := false
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))
}
typOK = typ != typeExprPlaceholder && typ != typeExprTypeExpr
case a.KTypeExpr:
typOK = typ == typeExprTypeExpr
default:
typOK = typ == typeExprPlaceholder
}
if !typOK {
return fmt.Errorf("check: internal error: %s has incorrect type, %s",
nodeDebugString(tm, o), typ.Str(tm))
}
if o.Kind() == a.KExpr {
o := o.AsExpr()
if typ.IsIdeal() && o.ConstValue() == nil {
return fmt.Errorf("check: internal error: expression %q has ideal number type "+
+3 -2
View File
@@ -36,9 +36,10 @@ var (
var (
typeExprGeneric1 = a.NewTypeExpr(0, t.IDBase, t.IDDagger1, nil, nil, nil)
typeExprGeneric2 = a.NewTypeExpr(0, t.IDBase, t.IDDagger2, nil, nil, nil)
typeExprIdeal = a.NewTypeExpr(0, t.IDBase, t.IDDoubleZ, nil, nil, nil)
typeExprIdeal = a.NewTypeExpr(0, t.IDBase, t.IDQIdeal, nil, nil, nil)
typeExprList = a.NewTypeExpr(0, t.IDBase, t.IDDollar, nil, nil, nil)
typeExprPlaceholder = a.NewTypeExpr(0, t.IDBase, t.IDPilcrow, nil, nil, nil)
typeExprPlaceholder = a.NewTypeExpr(0, t.IDBase, t.IDQPlaceholder, nil, nil, nil)
typeExprTypeExpr = a.NewTypeExpr(0, t.IDBase, t.IDQTypeExpr, nil, nil, nil)
typeExprU8 = a.NewTypeExpr(0, t.IDBase, t.IDU8, nil, nil, nil)
typeExprU16 = a.NewTypeExpr(0, t.IDBase, t.IDU16, nil, nil, nil)
+1 -1
View File
@@ -1001,7 +1001,7 @@ swtch:
default:
return fmt.Errorf("check: %q is not a type", typ.Str(q.tm))
}
setPlaceholderMBoundsMType(typ.AsNode())
typ.AsNode().SetMType(typeExprTypeExpr)
return nil
}