vishapoberon / compiler

vishap oberon compiler
http://oberon.vishap.am
GNU General Public License v3.0
186 stars 25 forks source link

add a warning for type aliasing #49

Closed norayr closed 7 years ago

norayr commented 7 years ago

warn programmer when facing

TYPE INTEGER=LONGINT

or

TYPE LONGINT = REAL

alike type aliases. it is useful to know when compiling a module about those.

dcwbrown commented 7 years ago

Would it make sense to warn when any built-in (predefined) type is redefined? Or just a subset?

diegosardina commented 7 years ago

In my opinion the issue is more general.

Redefinition of predefined constants, types and procedures/functions may cause code malfunctions or unexpected results. A warning makes sense for me, I expect this by an industrial quality compiler.

Type aliasing of predefined types leads to bizarre code like this:

MODULE test;
  TYPE INTEGER = REAL;
  VAR i : INTEGER;
BEGIN
  i := 3.14
END test.

For this reason Wirth removed type aliasing in Oberon-07.

For the same reason TRUE, FALSE and NIL were promoted to keyword in Oberon-07 to avoid redefinition. OP2 (here) also promoted these constants to keywords, but Ofront seems to keep them as predefined constants, maybe because it doesn't reflect Oberon-2 report.

norayr commented 7 years ago

recent merge added 'redefining standard predefined type' warning. might not be implemented the best way though, but works.

   5:      INTEGER = REAL;
                    ^
  pos    68  warning 310  redefining standard predefined type
norayr commented 7 years ago

ok closing.