From: Mehdi Saada <00120260a@gmail.com>
Subject: compiler confusion, overloading and "subtype mark required in this context"
Date: Sun, 7 Feb 2021 01:15:58 -0800 (PST) [thread overview]
Message-ID: <2241c895-8d4d-40fc-bf42-aa1c3daa0167n@googlegroups.com> (raw)
In an exo to build a rational integers package, I'm having the surprise to get a heapload of "context requires function call, found procedure name". While there is no procedure of these names.
function "+" (R1: T_rational; R2: T_rational) return T_rational is
(if (denom(R1) = denom(R2)) then (ENUM(R1) + ENUM(r2))/ denom(R1)
else (DENOM(R2)*ENUM(R1) + denom(r1)*ENUM(r2))/DENOM(R1)*denom(R2));
function denom (fraction: T_rational) return Positive is (fraction.denom);
function enum (fraction: T_rational) return Natural is (fraction.ENUM);
with usually a "no candidate interpretations match the actuals:" for the same stuff. There are several overloaded operators, but each time with different profiles so I'm very surprised it could cause trouble.
Another kind of oddity: several
function "+" (R1: T_rational; R2: T_rational) return T_rational is
(if (denom(R1) = denom(R2)) then (ENUM(R1) + ENUM(r2))/ denom(R1)
else (DENOM(R2)*ENUM(R1) + denom(r1)*ENUM(r2))/DENOM(R1)*denom(R2));
cause "ambiguous expression (cannot resolve "+")" with "possible interpretation". -- here it picks
function "+" (R1: T_rational; R2: T_rational) return T_rational;
as an interpretation, which is bullocks since obviously I'm calling on Integer operations, between enum() and denom(), integer and natural, then calling on the constructor "/" who is the only "/" with the specific profile
function "/" (N: Integer; D: Integer) return T_rational;
additional questions. I already looked up the rm. is there an attribute to 'min/'max integer without the sign (I "abs"ed them) ?
Last one:
The commented lines:
function Get_Line return T_rational is
use ada.Integer_Text_IO;
begin
loop
declare
S: string := Get_Line;
Enume: integer;
Denomi: Positive; ---- ##########
Ind : Natural range 0..1 := 0;
sign : T_SIGN := Positive;
Last: Positive;
begin
if S(1) = '-' then SIGN := negative; ind := 0; end if;
Get(S(s'First+ind..s'Last), Enume, Last);
if last = S'Last then return (IF SIGN = NEGATIVE => -Enume/1 else ENUMe/1); ----------######
Both last ones are "subtype mark required in this context" while he's refering to: type T_SIGN is (positive,negative);
But how can there be confusion ?
Thanks. this exo is suprisingly taxing... the numbers of details that go wrong !
next reply other threads:[~2021-02-07 9:15 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-07 9:15 Mehdi Saada [this message]
2021-02-07 10:59 ` compiler confusion, overloading and "subtype mark required in this context" AdaMagica
2021-02-07 12:56 ` Mehdi Saada
2021-02-11 3:03 ` Randy Brukardt
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox