Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple bugs in typeguard. #16

Closed
valexey opened this issue Aug 30, 2013 · 5 comments
Closed

Multiple bugs in typeguard. #16

valexey opened this issue Aug 30, 2013 · 5 comments

Comments

@valexey
Copy link
Contributor

valexey commented Aug 30, 2013

Typeguard rules:

The typeguard v(T0) asserts that v is of type T0, i.e. it aborts program execution, if it is not of type T0. The guard is applicable, if

  1. T0 is an extension of the declared type T of v, and if
  2. v is a variable parameter of record type, or v is a pointer

About pointers and extension types:

Pointer types inherit the extension relation of their base types, if there is any. If a type T is an extension of T0 and P is a pointer type bound to T, then P is also an extension of P0, the pointer type bound to T0.

(bad) - marks wrong compiler behaviour
(good) - marks correct compiler behaviour

MODULE test; 

TYPE 
 Parent    = RECORD END; 
 ParentPtr = POINTER TO Parent; 
 ChildPtr1 = POINTER TO RECORD (Parent) a : INTEGER END; 
 Child     = RECORD (Parent) a : INTEGER END; 
 ChildPtr2 = POINTER TO Child; 
VAR 
 ptr : ParentPtr;
 parent : Parent;
 child  : Child;

PROCEDURE Tst0(VAR p : Parent);
BEGIN
(* good *) p(Child).a := 42; (* must be ok, and there is ok -- ok *)
END Tst0;

PROCEDURE Tst1(p : Parent);
BEGIN
(* bad *) p(Child).a := 42; (* must be error, but there is ok *)
END Tst1;

BEGIN 
(* bad *)   ptr(ChildPtr1).a := 42; (* must be ok, but there is compile error *)
(* bad *)   ptr(ChildPtr2).a := 42; (* must be ok, but there is compile error *)
(* bad *)   parent(Child).a := 42; (* must be error (parent is not variable parameter of function), but there is ok *)
(* good *)  child(Parent).a := 42; (* must be error, and there is error -- ok *)
END test. 
@vladfolts
Copy link
Owner

Record parameter should be OK to cast regardless of its VAR attribute (of course respecting read-only nature of non-VAR parameter). There is no meaning in prohibiting a type guard for non-VAR record parameters.

@valexey
Copy link
Contributor Author

valexey commented Sep 2, 2013

non-VAR parameter can be passed by value (in some realizations) instead of by reference (also there is mix case - some records passed by reference, and some by value). Also according language report (and there is no ambiguity in this case) compiler MUST report error if programmer tries to use typeguard for VAL-record parameter of procedure.

@vladfolts
Copy link
Owner

OK. So O7 does not support immutable "message bus"? ;)

@valexey
Copy link
Contributor Author

valexey commented Sep 3, 2013

Yep :-) Also BlackBox uses only mutable message bus.

@vladfolts
Copy link
Owner

Partially fixed (to fix variables/val-parameters case).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants