diff --git a/lang/ast/ast.go b/lang/ast/ast.go index f7b77e46..b687e8e7 100644 --- a/lang/ast/ast.go +++ b/lang/ast/ast.go @@ -716,7 +716,7 @@ func (n *TypeExpr) IsBool() bool { } func (n *TypeExpr) IsIdeal() bool { - return n.id0 == 0 && n.id1 == t.IDBase && n.id2 == t.IDDoubleZ + return n.id0 == 0 && n.id1 == t.IDBase && n.id2 == t.IDQIdeal } func (n *TypeExpr) IsIOType() bool { diff --git a/lang/check/check.go b/lang/check/check.go index 18788e08..b03e3830 100644 --- a/lang/check/check.go +++ b/lang/check/check.go @@ -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 "+ diff --git a/lang/check/resolve.go b/lang/check/resolve.go index 1119bca8..92346952 100644 --- a/lang/check/resolve.go +++ b/lang/check/resolve.go @@ -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) diff --git a/lang/check/type.go b/lang/check/type.go index a45e6f47..6361782b 100644 --- a/lang/check/type.go +++ b/lang/check/type.go @@ -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 } diff --git a/lang/token/list.go b/lang/token/list.go index a21b0aa7..e92e8592 100644 --- a/lang/token/list.go +++ b/lang/token/list.go @@ -416,16 +416,17 @@ const ( IDIOWriter = ID(0x113) IDStatus = ID(0x114) - IDT1 = ID(0x11A) - IDT2 = ID(0x11B) - IDDagger1 = ID(0x11C) - IDDagger2 = ID(0x11D) + IDT1 = ID(0x118) + IDT2 = ID(0x119) + IDDagger1 = ID(0x11A) + IDDagger2 = ID(0x11B) - IDPilcrow = ID(0x11E) + IDQPlaceholder = ID(0x11D) + IDQTypeExpr = ID(0x11E) - // It is important that IDDoubleZ is right next to the IDI8..IDU64 block. + // It is important that IDQIdeal is right next to the IDI8..IDU64 block. // See the ID.IsNumTypeOrIdeal method. - IDDoubleZ = ID(0x11F) + IDQIdeal = ID(0x11F) IDI8 = ID(0x120) IDI16 = ID(0x121) @@ -675,17 +676,21 @@ var builtInsByID = [nBuiltInIDs]string{ IDDagger1: "†", // U+2020 DAGGER IDDagger2: "‡", // U+2021 DOUBLE DAGGER - // IDPilcrow is used by the type checker to build a placeholder MType for - // AST nodes that aren't expression nodes, such as struct definition nodes - // and statement nodes. Its presence means that the non-expression node is - // type checked. - IDPilcrow: "¶", // U+00B6 PILCROW SIGN + // IDQPlaceholder is used by the type checker to build an artificial MType + // for AST nodes that aren't expression nodes or type expression nodes, + // such as struct definition nodes and statement nodes. Its presence means + // that the node is type checked. + IDQPlaceholder: "«Placeholder»", - // IDDoubleZ is used by the type checker as a dummy-valued built-in ID to - // represent an ideal integer type (in mathematical terms, the integer ring - // ℤ), as opposed to a realized integer type whose range is restricted. For - // example, the base.u16 type is restricted to [0x0000, 0xFFFF]. - IDDoubleZ: "ℤ", // U+2124 DOUBLE-STRUCK CAPITAL Z + // IDQTypeExpr is used by the type checker to build an artificial MType for + // type expression AST nodes. + IDQTypeExpr: "«TypeExpr»", + + // IDQIdeal is used by the type checker to build an artificial MType for + // ideal integers (in mathematical terms, the integer ring ℤ), as opposed + // to a realized integer type whose range is restricted. For example, the + // base.u16 type is restricted to [0x0000, 0xFFFF]. + IDQIdeal: "«Ideal»", // Change MaxIntBits if a future update adds an i128 or u128 type. IDI8: "i8",