raz / commit e3839b4b

commit
e3839b4b5e95994fbe8d1cb645459a5a28163bf0
author
Luis <42945842+ldiaz94@users.noreply.github.com>
date
parent
ca1d9f1c
PROPOSALS: an enumeration's name read against the type it is given to

patch · log

1 file changed, +39 -0

PROPOSALS.md modified +39 -0

@@ -562,3 +562,42 @@
562562
563563 Met in concha's `Ccore`, in `bufVal` and `listVal`, and in `Sys` over
564564 C, before each call that takes a buffer.
565+
566+## An enumeration's name read against the type it is given to
567+
568+Two enumerations of a scope may share a name, and then the name alone
569+is an error: "the type is never taken from where the name stands"
570+(5.7). So a table of records, which names its enumerations on every
571+row, must write the type out on each row where the name is shared,
572+though the field says which enumeration it is:
573+
574+```
575+type
576+ MenuAction = (close, run, complete);
577+ BlockKind = (time, run, window);
578+ MenuKey = record sym: INT; act: MenuAction; end;
579+ Block = record kind: BlockKind; arg: []U8; end;
580+const
581+ MenuKeys: []MenuKey = [{sym: 13, act: run}]; (* an error: MenuAction.run or BlockKind.run *)
582+ Blocks: []Block = [{kind: run, arg: "date"}]; (* and so is this *)
583+```
584+
585+Adding `BlockKind`, with its `run`, broke `MenuKeys`, which had
586+compiled until then: a name added to one table reaches into the other.
587+
588+The proposal: where a value is given to a place whose type is an
589+enumeration, a name of that enumeration written alone is that name,
590+though another enumeration of the scope has it too. The places are the
591+right side of an assignment, a field of a record or variant written
592+with braces, a value parameter, a `return`, and the other side of a
593+relation with a value of the type. Everywhere else, and wherever the
594+rule of 5.7 names something already (a constant, a variable or a
595+procedure of the scope that isn't an enumeration's name), it stays as
596+it is. A program that compiles today means the same; only some of the
597+programs refused today compile, so it breaks none.
598+
599+It costs a line of 5.7, and in the compiler, a type passed down to the
600+lookup of a name where the parser knows it.
601+
602+Met in mosaico's `Mconfig`, where `MenuAction.run` and a status block's
603+kind `run` met; the block's kind was renamed `command`.