Re: Un comportement que je n'arrive pas à expliquer...
"Jean-Pierre Rosen" (via ada-france Mailing List) <[email protected]> Wed, 13 Sep 2023 19:48:09 +0200
| Newsgroups | gmane.comp.lang.ada.france |
|---|---|
| Organization | Adalog |
| Message-ID | <[email protected]> |
This is a multi-part message in MIME format. --------------HaVoEwjdPq65xvx1iCArp72V Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Le 01/09/2023 à 12:59, Sowebio - Développement (via ada-france Mailing List) a écrit : > > J'aimerai comprendre pourquoi l'assignation de chaînes littérales est > correcte dans un if then else classique et pas dans une expression > ternaire (if then else) ou elle redevient visiblement une > Standard.String ? > > > Merci d'avance d'éclairer ma lanterne ;) > Je ne peux pas répondre très précisément (à part Tucker Taft et Randy Bruckardt, je ne sais pas trop qui pourrait...) mais en gros la difficulté pour résoudre les surcharges est de savoir si le contexte externe détermine le type de ce qui est à l'intérieur, ou si c'est dans l'autre sens. Dans le cas d'une affectation, le contexte externe détermine un "type attendu" unique, donc ça marche. Dans le cas d'une expression "if", c'est plus compliqué. Il me semble d'après 4.5.7(9/3) que ça devrait marcher, puisque "If aconditional_expressionis expected to be of a type/T/, then each/dependent_/expressionof theconditional_expressionis expected to be of type/T". / Ca vaut le coup de poser la question à AdaCore ou d'essayer avec un autre compilateur... NB: c'est une mauvaise idée que d'appeler un type utilisateur "String", ou de n'importe quel autre nom défini dans Standard. Comme Standard est implicitement le parent de toutes les autres unités, les types y sont toujours directement visibles, et préférés aux types synonymes que l'on pourrait croire directement visibles par une clause "use". Ca crée souvent des confusions, et ça peut jouer dans ton cas. -- J-P. Rosen Adalog 2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX https://www.adalog.fr https://www.adacontrol.fr _______________________________________________ Ada-france mailing list [email protected] --------------HaVoEwjdPq65xvx1iCArp72V Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> </head> <body> <div class="moz-cite-prefix">Le 01/09/2023 à 12:59, Sowebio - Développement (via ada-france Mailing List) a écrit :<br> </div> <blockquote type="cite" cite="mid:[email protected]"> <p>J'aimerai comprendre pourquoi l'assignation de chaînes littérales est correcte dans un if then else classique et pas dans une expression ternaire (if then else) ou elle redevient visiblement une Standard.String ?</p> <p><br> </p> <p>Merci d'avance d'éclairer ma lanterne ;)</p> </blockquote> <div class="moz-signature">Je ne peux pas répondre très précisément (à part Tucker Taft et Randy Bruckardt, je ne sais pas trop qui pourrait...) mais en gros la difficulté pour résoudre les surcharges est de savoir si le contexte externe détermine le type de ce qui est à l'intérieur, ou si c'est dans l'autre sens. Dans le cas d'une affectation, le contexte externe détermine un "type attendu" unique, donc ça marche. Dans le cas d'une expression "if", c'est plus compliqué. Il me semble d'après 4.5.7(9/3) que ça devrait marcher, puisque "<span style="color: rgb(0, 0, 0); font-family: "Times New Roman", Times, serif; font-size: medium; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 240); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; display: inline !important; float: none;">If a<span> </span></span><span class="swiss" style="font-family: Arial, Helvetica, sans-serif; font-size: 14.72px; color: rgb(0, 0, 0); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 240); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><a moz-do-not-send="true">conditional_expression</a></span><span style="color: rgb(0, 0, 0); font-family: "Times New Roman", Times, serif; font-size: medium; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 240); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; display: inline !important; float: none;"><span> </span>is expected to be of a type<span> </span></span><i style="color: rgb(0, 0, 0); font-family: "Times New Roman", Times, serif; font-size: medium; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 240); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">T</i><span style="color: rgb(0, 0, 0); font-family: "Times New Roman", Times, serif; font-size: medium; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 240); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; display: inline !important; float: none;">, then each<span> </span></span><i style="color: rgb(0, 0, 0); font-family: "Times New Roman", Times, serif; font-size: medium; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 240); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">dependent_</i><span class="swiss" style="font-family: Arial, Helvetica, sans-serif; font-size: 14.72px; color: rgb(0, 0, 0); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 240); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><a moz-do-not-send="true">expression</a></span><span style="color: rgb(0, 0, 0); font-family: "Times New Roman", Times, serif; font-size: medium; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 240); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; display: inline !important; float: none;"><span> </span>of the<span> </span></span><span class="swiss" style="font-family: Arial, Helvetica, sans-serif; font-size: 14.72px; color: rgb(0, 0, 0); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 240); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><a moz-do-not-send="true">conditional_expression</a></span><span style="color: rgb(0, 0, 0); font-family: "Times New Roman", Times, serif; font-size: medium; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 240); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; display: inline !important; float: none;"><span> </span>is expected to be of type<span> </span></span><i style="color: rgb(0, 0, 0); font-family: "Times New Roman", Times, serif; font-size: medium; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 240); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">T". <br> </i></div> <div class="moz-signature">Ca vaut le coup de poser la question à AdaCore ou d'essayer avec un autre compilateur...</div> <div class="moz-signature"><br> </div> <div class="moz-signature">NB: c'est une mauvaise idée que d'appeler un type utilisateur "String", ou de n'importe quel autre nom défini dans Standard. Comme Standard est implicitement le parent de toutes les autres unités, les types y sont toujours directement visibles, et préférés aux types synonymes que l'on pourrait croire directement visibles par une clause "use". Ca crée souvent des confusions, et ça peut jouer dans ton cas.<br> </div> <div class="moz-signature">-- <br> J-P. Rosen<br> Adalog<br> 2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX<br> <a class="moz-txt-link-freetext" href="https://www.adalog.fr" moz-do-not-send="true">https://www.adalog.fr</a> <a class="moz-txt-link-freetext" href="https://www.adacontrol.fr" moz-do-not-send="true">https://www.adacontrol.fr</a> </div> <div style="background: transparent; border: none; clear: both; display: block; float: none; position: static"><br/>_______________________________________________<br/>Ada-france mailing list<br/>[email protected]</div></body> </html> --------------HaVoEwjdPq65xvx1iCArp72V--