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,FREEMAIL_FROM, WEIRD_QUOTING autolearn=ham autolearn_force=no version=3.4.5-pre1 Path: eternal-september.org!reader02.eternal-september.org!aioe.org!AJ7J9qECrnxaqcRJ0agR7g.user.gioia.aioe.org.POSTED!not-for-mail From: Blady Newsgroups: comp.lang.ada Subject: Type inference with String_Literal. Date: Sat, 26 Dec 2020 10:12:53 +0100 Organization: Aioe.org NNTP Server Message-ID: NNTP-Posting-Host: AJ7J9qECrnxaqcRJ0agR7g.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.5.1 X-Notice: Filtered by postfilter v. 0.9.2 Content-Language: en-US X-Mozilla-News-Host: news://nntp.aioe.org:119 Xref: reader02.eternal-september.org comp.lang.ada:60942 List-Id: Hello, In the following test program, line 16 the string literal is correctly inferred to Wide_Wide_String and line 17 the string literal is correctly inferred to My_Type1 as aspect String_Literal is defined line 7 for this type. But line 18, GNAT reports a type match error in a "if expression" with string literals. String literal in the "if expression" has to qualified by My_Type1 as in line 20: 1. with Ada.Wide_Wide_Text_IO; 2. procedure Test_20201225_str_lit is 3. 4. type My_Type1 (Length : Natural) is record 5. Value : Wide_Wide_String (1 .. Length); 6. end record with 7. String_Literal => From_String1; 8. function From_String1 (Value : Wide_Wide_String) return My_Type1 is ((Length => Value'Length, Value => Value)); 9. procedure Print1 (Self : My_Type1) is 10. begin 11. Ada.Wide_Wide_Text_IO.Put_Line (Self.Value); 12. end Print1; 13. 14. function Test return Boolean is (True); 15. 16. S : Wide_Wide_String := (if Test then "test0" else ""); 17. MV0 : My_Type1 := "test0"; 18. MV1 : My_Type1 := (if Test then "test1" else ""); | >>> expected type "My_Type1" defined at line 4 >>> found a string type 19. MV2 : My_Type1 := My_Type1'(if Test then "test2" else ""); | >>> expected type "My_Type1" defined at line 4 >>> found a string type 20. MV3 : My_Type1 := (if Test then My_Type1'("test3") else ""); 21. 22. begin 23. Print1 ("Test ""string"""); 24. Print1 ("88"); 25. Print1 (MV1); 26. Print1 (MV2); 27. end Test_20201225_str_lit; Shouldn't GNAT set the type My_Type1 for the string literal in line 18 as it does line 17? Thanks, Pascal.