# Unable to resolve expression, why?

**URL:** <https://forum.ada-lang.io/t/unable-to-resolve-expression-why/1001>\
**Category:** General\
**Created:** [July 20, 2024, 12:22pm UTC](https://forum.ada-lang.io/t/unable-to-resolve-expression-why/1001 "2024-07-20T12:22:14Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![m8vl4](https://forum.ada-lang.io/letter_avatar_proxy/v4/letter/m/6de8d8/32.png) [@m8vl4](https://forum.ada-lang.io/u/m8vl4)\
**Post date:** [July 20, 2024, 12:22pm UTC](https://forum.ada-lang.io/t/unable-to-resolve-expression-why/1001/1 "2024-07-20T12:22:14Z")

</div>

```ada
-- In file dim_mats.adB:
  WITH Ada.Text_io ; USE Ada.Text_io ;
  WITH Ada.strings.unbounded ; USE Ada.strings.unbounded ;
  PACKAGE Dim_mats IS  
    TYPE mat3_unb_str IS ARRAY
        ( Natural RANGE <>, Natural RANGE <>, Natural RANGE <>) 
        OF Unbounded_string ;
    SUBTYPE arr3_unb_str IS mat3_unb_str( 0..2, 0..11, 0..2) ;
  END Dim_mats ;

-- In file procdurs.adB:
  WITH Dim_mats ; USE Dim_mats ;
  PROCEDURE foo IS
    foo_unb_str: Unbounded_string ;
    idx1_nat, idx2_nat, idx3_nat: Natural := 1 ;
  BEGIN
    foo_unb_str := To_unbounded_string( "foobar") ;
    arr3_unb_str( idx1_nat, idx2_nat, idx3_nat) := foo_unb_str ; 
    -- <<<<< Unable to resolve expression
  END foo ;

```

---

<div class="post-metadata">

**Author:** ![DrPi](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/drpi/32/225_2.png) [@DrPi](https://forum.ada-lang.io/u/DrPi)\
**Post date:** [July 20, 2024, 12:56pm UTC](https://forum.ada-lang.io/t/unable-to-resolve-expression-why/1001/2 "2024-07-20T12:56:14Z")

</div>

`arr3_unb_str` is a subtype, not a variable. You can’t assign to it.

---

<div class="post-metadata">

**Author:** ![m8vl4](https://forum.ada-lang.io/letter_avatar_proxy/v4/letter/m/6de8d8/32.png) [@m8vl4](https://forum.ada-lang.io/u/m8vl4)\
**Post date:** [July 20, 2024, 5:14pm UTC](https://forum.ada-lang.io/t/unable-to-resolve-expression-why/1001/3 "2024-07-20T17:14:57Z")

</div>

Thanks for comment.

In RM95, the search phrase “variable of subtype” appears in an obscure note at 3.5.57 under scalar types, but not about the instant unbounded\_string.  
Therefore I assume the legal rule that subtypes must be renamed to variable names is in the Ada folklore.

---

<div class="post-metadata">

**Author:** ![jere](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/jere/32/87_2.png) [@jere](https://forum.ada-lang.io/u/jere)\
**Post date:** [July 20, 2024, 5:46pm UTC](https://forum.ada-lang.io/t/unable-to-resolve-expression-why/1001/4 "2024-07-20T17:46:48Z")

</div>

The pertinent section for your example is probably [5.2 Assignment Statements](http://www.ada-auth.org/standards/22rm/html/RM-5-2.html) which has

> assignment\_statement ::= _variable\__ [name](http://www.ada-auth.org/standards/22rm/html/RM-4-1.html#S0091) := [expression](http://www.ada-auth.org/standards/22rm/html/RM-4-4.html#S0132);

Notice it specifies “variable” name rather than “subtype” name. Hopefully that clears it up some!

---

<div class="post-metadata">

**Author:** ![m8vl4](https://forum.ada-lang.io/letter_avatar_proxy/v4/letter/m/6de8d8/32.png) [@m8vl4](https://forum.ada-lang.io/u/m8vl4)\
**Post date:** [July 20, 2024, 7:22pm UTC](https://forum.ada-lang.io/t/unable-to-resolve-expression-why/1001/5 "2024-07-20T19:22:00Z")

</div>

I see.[reply requires 20 chars]

---

<div class="post-metadata">

**Author:** ![DrPi](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/drpi/32/225_2.png) [@DrPi](https://forum.ada-lang.io/u/DrPi)\
**Post date:** [July 20, 2024, 7:25pm UTC](https://forum.ada-lang.io/t/unable-to-resolve-expression-why/1001/6 "2024-07-20T19:25:48Z")

</div>

A subtype is some sort of restricted type.  
The `Integer` type represents all integers usable on the machine (32 or 64 bits).  
The `Natural` subtype is an `Integer` type restricted to positive and null (0) values.  
The `Positive` subtype is an `Integer` type restricted to only positive values.

A variable is an instanciation of a type/subtype.  
`My_Variable : Integer;`  
`My_Var2 : Positive;`

A variable can be assigned.  
`My_Variable := -10;`  
`My_Var2 := 10;`

---

<div class="post-metadata">

**Author:** ![m8vl4](https://forum.ada-lang.io/letter_avatar_proxy/v4/letter/m/6de8d8/32.png) [@m8vl4](https://forum.ada-lang.io/u/m8vl4)\
**Post date:** [July 20, 2024, 7:26pm UTC](https://forum.ada-lang.io/t/unable-to-resolve-expression-why/1001/7 "2024-07-20T19:26:48Z")

</div>

ok ty [reply requires 20 chars]
