comp.lang.ada
 help / color / mirror / Atom feed
From: Niklas Holsti <niklas.holsti@tidorum.invalid>
Subject: Re: attributes on expressions, not name
Date: Wed, 28 Feb 2018 19:55:47 +0200
Date: 2018-02-28T19:55:47+02:00	[thread overview]
Message-ID: <ffo8p4FlfijU1@mid.individual.net> (raw)
In-Reply-To: <b718fabf-b7fd-4b97-b633-7082a0ab7214@googlegroups.com>

On 18-02-28 18:57 , Mehdi Saada wrote:
> why aren't attributes allowed on expressions ?
> Like LINE'Length, assuming LINE is a function returning STRING.

There is no such limitation.

RM 4.1.4: attribute_reference ::= prefix'attribute_designator

RM 4.1: prefix ::= name ...

RM 4.1; name ::= ... function_call ...

> The type of an expression is always static,

The type of the value returned by a function call is known only after 
compile-time overload resolution, which depends on the context of the 
expression. Applying an attribute to (the result of) a function call 
does not always provide enough context to resolve overloading.

In your example, there could be several different functions called LINE, 
some returning types to which the Length attribute could apply, and some 
returning types to which it does not apply. It is not clear which of 
these functions should be called.

If I have one function LINE return String, and another LINE return 
Integer, and try to compute LINE'Length, GNAT tells me:

func_attr.adb:22:41: ambiguous prefix for "Length" attribute

Is that the error message you get?

-- 
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
       .      @       .


  reply	other threads:[~2018-02-28 17:55 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-28 16:57 attributes on expressions, not name Mehdi Saada
2018-02-28 17:55 ` Niklas Holsti [this message]
2018-02-28 18:38   ` Alejandro R. Mosteo
2018-02-28 21:36     ` Mehdi Saada
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox