# Implicit Generic Parameter Conversion - Odd Error Message

**URL:** <https://chapel.discourse.group/t/implicit-generic-parameter-conversion-odd-error-message/35500>\
**Category:** Users\
**Created:** [July 18, 2024, 9:04am UTC](https://chapel.discourse.group/t/implicit-generic-parameter-conversion-odd-error-message/35500 "2024-07-18T09:04:41Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![damianmoz](https://yyz2.discourse-cdn.com/free1/user_avatar/chapel.discourse.group/damianmoz/32/319_2.png) [@damianmoz](https://chapel.discourse.group/u/damianmoz)\
**Post date:** [July 18, 2024, 9:04am UTC](https://chapel.discourse.group/t/implicit-generic-parameter-conversion-odd-error-message/35500/1 "2024-07-18T09:04:41Z")

</div>

Consider the following code:

```chapel
...
// Compute x*2**n with minimum work (e.g. multiplications)
// The C version of this is 43 lines of assembler with GCC 11
// So using this as an inline routine is probably justifiable

inline proc scale(in x : real(?w), n : int(w))
{
   ...
   // blah-blah-blah
   ...
}
proc main
{
    writef("scale %12.6xr\n", scale(0x1.5p+127:real(32), -270));
    return(0);
}

```

I compiled this and it complains:

```Chapel
scale.chpl:66: In function 'main':
scale.chpl:68: warning: deprecated use of implicit conversion when passing to a generic formal
scale.chpl:68: note: actual with type 'real(32)'
scale.chpl:15: note: is passed to formal with type 'real(?w)'
note: consider adding a cast to 'real(64)' or an overload to handle 'real(32)'

```

That is clearly wrong. The issue has nothing to do with the **real** (?_w_) parameter. The issue is the integer. If I change **int** (?_w_) tp **integral** , the complaint disappears.

I can post the entire code but the issue has nothing to with the internals of _scale_().

---

<div class="post-metadata">

**Author:** ![lydia](https://avatars.discourse-cdn.com/v4/letter/l/34f0e0/32.png) [@lydia](https://chapel.discourse.group/u/lydia)\
**Post date:** [July 18, 2024, 3:21pm UTC](https://chapel.discourse.group/t/implicit-generic-parameter-conversion-odd-error-message/35500/2 "2024-07-18T15:21:59Z")

</div>

Hi Damian,

I agree, that definitely seems wrong. Would you file a Github issue for it?

Thanks,  
Lydia

On 7/18/24 2:05 AM, Damian McGuckin via Chapel Programming Language wrote:

> [damianmoz] damianmoz [https://chapel.discourse.group/u/damianmoz](https://chapel.discourse.group/u/damianmoz)  
> July 18
> 
> Consider the following code:
> 
> |... // Compute x\*2\*\*n with minimum work (e.g. multiplications) // The  
> C version of this is 43 lines of assembler with GCC 11 // So using  
> this as an inline routine is probably justifiable inline proc scale(in  
> x : real(?w), n : int(w)) { ... // blah-blah-blah ... } proc main {  
> writef("scale %12.6xr\n", scale(0x1.5p+127:real(32), -270)); return(0); } |
> 
> I compiled this and it complains:
> 
> |scale.chpl:66: In function 'main': scale.chpl:68: warning: deprecated  
> use of implicit conversion when passing to a generic formal  
> scale.chpl:68: note: actual with type 'real(32)' scale.chpl:15: note:  
> is passed to formal with type 'real(?w)' note: consider adding a cast  
> to 'real(64)' or an overload to handle 'real(32)' |
> 
> That is clearly wrong. The issue has nothing to do with the  
> _real_(?/w/) parameter. The issue is the integer. If I change  
> _int_(?/w/) tp _integral_, the complaint disappears.
> 
> I can post the entire code but the issue has nothing to with the  
> internals of /scale/().
> 
> * * *
> 
> Visit Topic  
> [https://chapel.discourse.group/t/implicit-generic-parameter-conversion-odd-error-message/35500/1](https://chapel.discourse.group/t/implicit-generic-parameter-conversion-odd-error-message/35500/1)  
> or reply to this email to respond.
> 
> You are receiving this because you enabled mailing list mode.
> 
> To unsubscribe from these emails, click here  
> [https://chapel.discourse.group/email/unsubscribe/0356b8d1287e178d60cbd01d1a7bd26e9691ba3c0bf97d39ef9895a192bb34d9](https://chapel.discourse.group/email/unsubscribe/0356b8d1287e178d60cbd01d1a7bd26e9691ba3c0bf97d39ef9895a192bb34d9).

---

<div class="post-metadata">

**Author:** ![damianmoz](https://yyz2.discourse-cdn.com/free1/user_avatar/chapel.discourse.group/damianmoz/32/319_2.png) [@damianmoz](https://chapel.discourse.group/u/damianmoz)\
**Post date:** [July 19, 2024, 12:37am UTC](https://chapel.discourse.group/t/implicit-generic-parameter-conversion-odd-error-message/35500/3 "2024-07-19T00:37:22Z")

</div>

I was hoping for some insight into the problem so that I could submit a more intelligent sounding issue. If nobody replies before Monday, I will submit the issue as-is. When I get what looks like a very odd error, I always worry that it is the programmer who is triggering the error that is the odd part of the puzzle.

---

<div class="post-metadata">

**Author:** ![vass](https://yyz2.discourse-cdn.com/free1/user_avatar/chapel.discourse.group/vass/32/692_2.png) [@vass](https://chapel.discourse.group/u/vass)\
**Post date:** [July 19, 2024, 2:22am UTC](https://chapel.discourse.group/t/implicit-generic-parameter-conversion-odd-error-message/35500/4 "2024-07-19T02:22:30Z")

</div>

Hello Damian,

I agree with Lydia, this deserves an issue. Meanwhile here is some background.

We have decided to deprecate the interpretation of a `real(?w)` formal as stamping out one overload for real(32) and one for real(64). See [this comment in #20011](https://github.com/chapel-lang/chapel/issues/20011#issuecomment-1642075234). So the warning you are observing is the compiler's way to say that. The warning was added in [#22769](https://github.com/chapel-lang/chapel/pull/22769).

I am more concerned that the compiler dispatches to the overload for (64, 64)-bit arguments. My expectation and probably your intention as well are to invoke the one for (32, 32). I could not tell why this happens upon a cursory look a the [resolution rules in the spec](https://chapel-lang.org/docs/2.1/language/spec/procedures.html#determining-most-specific-functions) .

The closest I got was this clause: "Discard any candidates that have more formals that require `param` narrowing conversions than another candidate." However it is unclear to me from the text whether the conversion of `-270` to `int(32)` is "narrowing" or not. @mppf - any insights here?

Vass

---

<div class="post-metadata">

**Author:** ![damianmoz](https://yyz2.discourse-cdn.com/free1/user_avatar/chapel.discourse.group/damianmoz/32/319_2.png) [@damianmoz](https://chapel.discourse.group/u/damianmoz)\
**Post date:** [July 19, 2024, 3:24am UTC](https://chapel.discourse.group/t/implicit-generic-parameter-conversion-odd-error-message/35500/5 "2024-07-19T03:24:54Z")

</div>

> [@vass](#):
>
> We have decided to deprecate the interpretation of a `real(?w)` formal as stamping out one overload for real(32) and one for real(64). See [this comment in #20011](https://github.com/chapel-lang/chapel/issues/20011#issuecomment-1642075234). So the warning you are observing is the compiler's way to say that. The warning was added in [#22769](https://github.com/chapel-lang/chapel/pull/22769).

One of the things that attracted me to Chapel was that I could write a generic routine for an algorithm that would work if I fed it a floating point number of any size - 32-bit, 64-bit or even 128-bit. I only had to write one piece of code. Are you saying this is no longer true? Generally, a 32 bit integer serves my needs. If it does not, there is normally a comment why not.

The compile accepts my code if I declare that integer parameter to be **int** (32) (which is quite sound from a mathematical perspective even for a **real** (256)), i.e. the following works well and does not create any warnings:

```chapel
proc scale(in x : real(?w), n : int(32))
{
   ...
}

```

I guess I found the original error message a bit strange because the compiler was complaining about the **real** parameter rather than the **int** parameter which is where I actually had the problem. But you are talking about something else again so I am not sure I really have a total grasp of the underlying issue. Ho-ho.

That confusion was why I did not file an issue. I was worried my interpretation of the problem was twisted the wrong way. I was not even sure what the title of the issue should be. My own knowledge of the intricacies of dispatching to an overload is inadequate and parameter narrowing or widening sends my head spinning. So until I understood a bit more, I did not want to be writing waffle. I can do enough of that already without trying.

Thanks for the explanation.

---

<div class="post-metadata">

**Author:** ![damianmoz](https://yyz2.discourse-cdn.com/free1/user_avatar/chapel.discourse.group/damianmoz/32/319_2.png) [@damianmoz](https://chapel.discourse.group/u/damianmoz)\
**Post date:** [July 21, 2024, 7:20am UTC](https://chapel.discourse.group/t/implicit-generic-parameter-conversion-odd-error-message/35500/6 "2024-07-21T07:20:03Z")

</div>

Issue created. Feel free to change the title. I have no idea what Issue type it should have been.

---

<div class="post-metadata">

**Author:** ![mppf](https://avatars.discourse-cdn.com/v4/letter/m/94ad74/32.png) [@mppf](https://chapel.discourse.group/u/mppf)\
**Post date:** [July 22, 2024, 4:13pm UTC](https://chapel.discourse.group/t/implicit-generic-parameter-conversion-odd-error-message/35500/7 "2024-07-22T16:13:45Z")

</div>

@damianmoz -- I think as a general practice you should use those flags to warn for implicit conversions, if you are not already.

@vass -- I've responded to your question on the issue -- [Misleading Warning with Generic Arguments · Issue #25604 · chapel-lang/chapel · GitHub](https://github.com/chapel-lang/chapel/issues/25604#issuecomment-2243331777) .
