Remove the !? effect, leaving only ! and !??

This commit is contained in:
Nigel Tao committed 2018-12-29 13:36:38 +11:00
1 parent d4be1fdf72
commit 1ea32b3745
7 files changed
+20 -28

No files matched your search

+2 -6
View File
@@ -110,8 +110,7 @@ type Effect uint8
const (
EffectImpure = Effect(0x01)
EffectOptional = Effect(0x02) // TODO: rename to Statusful or Throws?
EffectCoroutine = Effect(0x04)
EffectCoroutine = Effect(0x02)
effectMask = Effect(0xFF)
)
@@ -120,7 +119,6 @@ func (e Effect) AsFlags() Flags { return Flags(e) }
func (e Effect) Pure() bool { return e == 0 }
func (e Effect) Impure() bool { return e&EffectImpure != 0 }
func (e Effect) Optional() bool { return e&EffectOptional != 0 }
func (e Effect) Coroutine() bool { return e&EffectCoroutine != 0 }
func (e Effect) WeakerThan(o Effect) bool { return e < o }
@@ -131,9 +129,7 @@ func (e Effect) String() string {
return ""
case EffectImpure:
return "!"
case EffectImpure | EffectOptional:
return "!?"
case EffectImpure | EffectOptional | EffectCoroutine:
case EffectImpure | EffectCoroutine:
return "!??"
}
return "‽INVALID_EFFECT‽"
+1 -1
View File
@@ -298,7 +298,7 @@ func (q *checker) bcheckStatement(n *a.Node) error {
case a.KRet:
n := n.AsRet()
lTyp := q.astFunc.Out()
if q.astFunc.Effect().Optional() {
if q.astFunc.Effect().Coroutine() {
lTyp = typeExprStatus
} else if lTyp == nil {
return fmt.Errorf("TODO: allow returning nothing")
+1 -1
View File
@@ -433,7 +433,7 @@ func (c *Checker) checkFuncSignature(node *a.Node) error {
}
setPlaceholderMBoundsMType(n.In().AsNode())
if out := n.Out(); out != nil {
if n.Effect().Optional() && n.Receiver()[0] != t.IDBase {
if n.Effect().Coroutine() && n.Receiver()[0] != t.IDBase {
return &Error{
Err: fmt.Errorf("func %s has ? effect but non-empty return type", n.QQID().Str(c.tm)),
Filename: n.Filename(),
+2 -2
View File
@@ -170,7 +170,7 @@ func (q *checker) tcheckStatement(n *a.Node) error {
case a.KRet:
n := n.AsRet()
lTyp := q.astFunc.Out()
if q.astFunc.Effect().Optional() {
if q.astFunc.Effect().Coroutine() {
lTyp = typeExprStatus
} else if lTyp == nil {
return fmt.Errorf("TODO: allow returning nothing")
@@ -545,7 +545,7 @@ func (q *checker) tcheckExprCall(n *a.Expr, depth uint32) error {
oTyp := f.Out()
if oTyp == nil {
if n.Effect().Optional() {
if n.Effect().Coroutine() {
n.SetMType(typeExprStatus)
} else {
n.SetMType(typeExprEmptyStruct)
+3 -3
View File
@@ -683,7 +683,7 @@ func (p *parser) parseAssignNode() (*a.Node, error) {
}
if op == t.IDEqQuestion {
if (rhs.Operator() != t.IDOpenParen) || (!rhs.Effect().Optional()) {
if (rhs.Operator() != t.IDOpenParen) || (!rhs.Effect().Coroutine()) {
return nil, fmt.Errorf(`parse: expected ?-function call after "=?", got %q at %s:%d`,
rhs.Str(p.tm), p.filename, p.line())
}
@@ -1170,8 +1170,8 @@ func (p *parser) parseEffect() a.Effect {
}
p.src = p.src[1:]
if p.peek1() != t.IDQuestion {
return a.EffectImpure | a.EffectOptional
panic("TODO: delete")
}
p.src = p.src[1:]
return a.EffectImpure | a.EffectOptional | a.EffectCoroutine
return a.EffectImpure | a.EffectCoroutine
}