From: Blady <p.p11@orange.fr>
Subject: Type inference with String_Literal.
Date: Sat, 26 Dec 2020 10:12:53 +0100 [thread overview]
Message-ID: <rs6uql$uj1$1@gioia.aioe.org> (raw)
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.
next reply other threads:[~2020-12-26 9:12 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-26 9:12 Blady [this message]
2020-12-27 5:26 ` Type inference with String_Literal Randy Brukardt
2021-01-02 9:43 ` Blady
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox