adolph@ssc-vax.UUCP (Mark C. Adolph) (09/14/88)
Given the following package specs, I'm getting errors which I'm confused about: 1 package Test_Pack_One is 2 3 type Enum_Type is (one, three, five, seven, nine); 4 5 end Test_Pack_One; 6 7 with Test_Pack_One; 8 package Test_Pack_Two is 9 10 subtype Enum_Type is Test_Pack_One.Enum_Type; 11 12 first_enum : Enum_Type := three; 13 second_enum : Enum_Type := Enum_Type'(three); 14 third_enum : Test_Pack_One.Enum_Type := 15 Test_Pack_One.Enum_Type'(three); 16 17 end Test_Pack_Two; Test_Pack_Two produces errors on the declarations of all three objects. The DEC Ada compiler says: 10 subtype Enum_Type is Test_Pack_One.Enum_Type; 11 12 first_enum : Enum_Type := three; .......................................1 %ADAC-E, (1) three is not declared [LRM 8.3] %ADAC-I, (1) Possibly a selected component of (or use clause for) package Test_Pack_One in Test_Pack_One at line 1 is intended; this would make enumeral three in Test_Pack_One at line 3 visible 13 second_enum : Enum_Type := Enum_Type'(three); ..................................................1 %ADAC-E, (1) three is not declared [LRM 8.3] %ADAC-I, (1) Possibly a selected component of (or use clause for) package Test_Pack_One in Test_Pack_One at line 1 is intended; this would make enumeral three in Test_Pack_One at line 3 visible 14 third_enum : Test_Pack_One.Enum_Type := 15 Test_Pack_One.Enum_Type'(three); .....................................................1 %ADAC-E, (1) three is not declared [LRM 8.3] %ADAC-I, (1) Possibly a selected component of (or use clause for) package Test_Pack_One in Test_Pack_One at line 1 is intended; this would make enumeral three in Test_Pack_One at line 3 visible The InterACT VAX/1750A cross-compiler, though less verbose, agrees: Detected near line 12 *** 435E-2: Identifier THREE is not visible Detected near line 13 *** 435E-2: Identifier THREE is not visible Detected near line 15 *** 435E-2: Identifier THREE is not visible Am I missing something, or is a USE clause absolutely required here? How can a type be visible, via either a SUBTYPE declaration or a WITH and selection, but not its values? Finally, assuming that this is correct, what is the rationale? -- -- Mark A. ...uw-beaver!ssc-vax!adolph
fred@cs.utexas.edu (Fred Hosch) (09/14/88)
In article <2223@ssc-vax.UUCP>, adolph@ssc-vax.UUCP (Mark C. Adolph) writes: > Given the following package specs, I'm getting errors which I'm > confused about: > > 1 package Test_Pack_One is > 2 > 3 type Enum_Type is (one, three, five, seven, nine); > 4 > 5 end Test_Pack_One; > 6 > 7 with Test_Pack_One; > 8 package Test_Pack_Two is > 9 > 10 subtype Enum_Type is Test_Pack_One.Enum_Type; > 11 > 12 first_enum : Enum_Type := three; ... LRM 3.5.1 states "this declaration (of an enumeration literal) is equivalent to the declaration of a parameterless function..." Either of the following will do without a use-clause: package TEST_PACK_ONE is type ENUM_TYPE is (ONE, THREE, FIVE, SEVEN); end TEST_PACK_ONE; with TEST_PACK_ONE; package TEST_PACK_TWO is subtype ENUM_TYPE is TEST_PACK_ONE.ENUM_TYPE; FIRST_ENUM: ENUM_TYPE := TEST_PACK_ONE.THREE; end TEST_PACK_TWO; or package TEST_PACK_ONE is type ENUM_TYPE is (ONE, THREE, FIVE, SEVEN); end TEST_PACK_ONE; with TEST_PACK_ONE; package TEST_PACK_TWO is type ENUM_TYPE is new TEST_PACK_ONE.ENUM_TYPE; FIRST_ENUM: ENUM_TYPE := THREE; end TEST_PACK_TWO; --- Fred Hosch fred@cs.utexas.edu
harrison@software.ORG (Tim Harrison) (09/16/88)
>> In article <2223@ssc-vax.UUCP>, adolph@ssc-vax.UUCP (Mark C. Adolph) writes: >> Given the following package specs, I'm getting errors which I'm >> confused about: >> >> 1 package Test_Pack_One is >> 2 >> 3 type Enum_Type is (one, three, five, seven, nine); >> 4 >> 5 end Test_Pack_One; >> 6 >> 7 with Test_Pack_One; >> 8 package Test_Pack_Two is >> 9 >> 10 subtype Enum_Type is Test_Pack_One.Enum_Type; >> 11 >> 12 first_enum : Enum_Type := three; >> 13 second_enum : Enum_Type := Enum_Type'(three); >> 14 third_enum : Test_Pack_One.Enum_Type := >> 15 Test_Pack_One.Enum_Type'(three); >> 16 >> 17 end Test_Pack_Two; Two solutions without a USE clause were provided by Fred Hosch <fred@cs.utexas.edu>. Another possible solution is: package Test_Pack_One is type Enum_Type is (one, three, five, seven, nine); end Test_Pack_One; with Test_Pack_One; package Test_Pack_Two is subtype Enum_Type is Test_Pack_One.Enum_Type; function three return Test_Pack_One.Enum_Type renames Test_Pack_One.three; first_enum : Enum_Type := three; end Test_Pack_Two; -- Tim Harrison Software Productivity Consortium Phone: (703) 391-1742 1880 Campus Commons Drive, North CSnet: harrison@software.org Reston, Virginia 22091 ARPAnet: harrison@ajpo.sei.cmu.edu