I want to write a "=" function, which can compare an A\_Access also against the null object. How do I need to write the "=" function, so that it works? For my try, see below.

The code produces a **raised CONSTRAINT\_ERROR : main.adb:14 access check failed**.

```
with Ada.Tags;
with Ada.Text_IO;

procedure Main is
   type A is tagged
      record
         a : Integer;
      end record;
   type A_Access is access all A'Class;

   function "=" (Left, Right : A_Access) return Boolean is
      use Ada.Tags;
   begin
      return (Left.all'Tag = Right.all'Tag and then Left.a = Right.a);
   end "=";
begin
   declare
      A_1 : A_Access := new A'(a => 1);
      A_2 : A_Access := null;
   begin
      if A_1 /= A_2 then
         Ada.Text_IO.Put_Line (":-)");
      end if;
   end;
end Main;

```

I also tried to check for null, but then, I get **raised STORAGE\_ERROR : stack overflow**. I think, here happens an infinite recursion?

```
function "=" (Left, Right : A_Access) return Boolean is
   use Ada.Tags;
begin
   if null = Left or null = Right then
      return False;
   else
      return (Left.all'Tag = Right.all'Tag and then Left.a = Right.a);
   end if;
end "=";

```