From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.5-pre1 Date: 11 Sep 91 18:43:18 GMT From: eachus@mitre-bedford.arpa (Robert I. Eachus) Subject: Re: why are these unknown identifiers? Message-ID: List-Id: In article <9109101616.aa26718@PARIS.ICS.UCI.EDU> jduarte@liege.ICS.UCI.EDU (Jo se Duarte) writes: ----------------------------------------- package X is type DIRECTIONS is (UP,DOWN,LEFT,RIGHT); end X; ----------------------------------------- with X; package Y is subtype DIRECTIONS is X.DIRECTIONS; end Y; ----------------------------------------- with TEXT_IO; use TEXT_IO; with Y; procedure BUG is V1 : Y.Directions := Y.UP; -- Y.UP is unknown V2 : Y.Directions := Y.DOWN; -- Y.DOWN is unknown begin null; end BUG; Can someone tell me why "Y.UP" and "Y.DOWN" are unknown identifiers within the procedure BUG? I have to "with X" and then assign X.UP and X.DOWN to V1 and V2 in order to compile this. Why is this the case? Is this an Ada pecularity or a compiler bug? -- You could say it is an Ada pecularity, because Ada is the only -- language with all the features necessary to run into it. A type -- declaration derives operations for the parent type, but a subtype -- does not. Therefore there is no function UP return DIRECTIONS in -- package Y. If you want to be able to refer to Y.UP you should say -- either: with X; package Y is type DIRECTIONS is new X.DIRECTIONS; -- derived functions declared here. end Y; -- or: with X; package Y is subtype DIRECTIONS is X.DIRECTIONS; function UP return DIRECTIONS renames X.UP; function DOWN return DIRECTIONS renames X.DOWN; function LEFT return DIRECTIONS renames X.LEFT; function RIGHT return DIRECTIONS renames X.RIGHT; end Y; -- The first approach will require explicit conversions when trying to -- assign values of type X.DIRECTIONS to variables of type -- Y.DIRECTIONS and vice-versa. (When designing Ada, this was thought -- to be a GOOD thing.) In the second case cross assignments are not -- a problem but saying use X; use Y; will result in neither -- declaration of UP being directly visible. Have fun, Robert I. Eachus with STANDARD_DISCLAIMER; use STANDARD_DISCLAIMER; function MESSAGE (TEXT: in CLEVER_IDEAS) return BETTER_IDEAS is... -- Robert I. Eachus with STANDARD_DISCLAIMER; use STANDARD_DISCLAIMER; function MESSAGE (TEXT: in CLEVER_IDEAS) return BETTER_IDEAS is...