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,WEIRD_QUOTING autolearn=ham autolearn_force=no version=3.4.5-pre1 Path: eternal-september.org!reader02.eternal-september.org!gandalf.srv.welterde.de!news.jacob-sparre.dk!franka.jacob-sparre.dk!pnx.dk!.POSTED.rrsoftware.com!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: Type inference with String_Literal. Date: Sat, 26 Dec 2020 23:26:33 -0600 Organization: JSA Research & Innovation Message-ID: References: Injection-Date: Sun, 27 Dec 2020 05:26:34 -0000 (UTC) Injection-Info: franka.jacob-sparre.dk; posting-host="rrsoftware.com:24.196.82.226"; logging-data="9335"; mail-complaints-to="news@jacob-sparre.dk" X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5931 X-RFC2646: Format=Flowed; Response X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.7246 Xref: reader02.eternal-september.org comp.lang.ada:60943 List-Id: Well, the rules for conditional expressions are separate from the rules for literals, so it certainly is possible for them to get different results. However, it appears to me that 4.5.7(13/3) applies to your examples on line 18 (the expression is "expected" to be of type My_Type1) and on line 19 (here the expression "shall resolve to" My_Type1). If that rule applies, then the dependent expressions should be resolved individually using My_Type1 - which obviously should work. So I think this is a bug in GNAT, although I'm not 100% certain (if the rule doesn't apply, then there isn't enough context to resolve the expression -- but I don't know why the rule wouldn't apply). Randy. "Blady" wrote in message news:rs6uql$uj1$1@gioia.aioe.org... > 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. >