# Inconsistent visibility with an inlined method

**URL:** https://talk.remobjects.com/t/inconsistent-visibility-with-an-inlined-method/12399
**Category:** Oxygene
**Tags:** oxygene
**Created:** [March 5, 2017, 4:49pm UTC](https://talk.remobjects.com/t/inconsistent-visibility-with-an-inlined-method/12399 "2017-03-05T16:49:56Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Maxim\_Volkov](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/m/b5a626/32.png) [@Maxim\_Volkov](https://talk.remobjects.com/u/Maxim_Volkov)
#### Post date: [March 5, 2017, 4:49pm UTC](https://talk.remobjects.com/t/inconsistent-visibility-with-an-inlined-method/12399/1 "2017-03-05T16:49:56Z")

</div>

I get a strange compiler error whenever I use an `inline` directive on a method.

The following code demonstrates this:

```
type
  Program = class
  private
      FValue: Integer; 
  public
    method GetValue: Integer; inline;    
  end;

implementation

method Program.GetValue: Integer;
begin
    result := FValue; // Visibility error here
end;

```

When compiling this code with Oxygene 9.0.97.2071 I get the following error:

Member “Program.FValue” is less visible than inlined method “method Program.GetValue(): Integer” it is used from

It goes away if I remove the `inline` directive. But I think even with the `inline` it is completely legitimate code and should not cause any compile errors.

---

<div class="post-metadata">

### Author: ![ck](https://talk.remobjects.com/user_avatar/talk.remobjects.com/ck/32/8740_2.png) [@ck](https://talk.remobjects.com/u/ck)
#### Post date: [March 5, 2017, 7:14pm UTC](https://talk.remobjects.com/t/inconsistent-visibility-with-an-inlined-method/12399/2 "2017-03-05T19:14:26Z")

</div>

Unfortunately, inline is a compiler feature, it’s inlined at the caller and the net and Java runtimes won’t allow foreign code access to private fields

---

<div class="post-metadata">

### Author: ![deltics](https://talk.remobjects.com/user_avatar/talk.remobjects.com/deltics/32/804_2.png) [@deltics](https://talk.remobjects.com/u/deltics)
#### Post date: [March 5, 2017, 9:24pm UTC](https://talk.remobjects.com/t/inconsistent-visibility-with-an-inlined-method/12399/3 "2017-03-05T21:24:03Z")

</div>

PMFJI: The behaviour of the underlying compilers can be argued as reasonable (by inlining the method, the visibility of the referenced members must be consistent with the inlined context). You can of course argue it the other way as well. But I guess it is what it is. 🙂

That being the case unless this is an excessively simplified example it looks to me as if this is really just a publicly readable privately writable member, so why not simply:

```
type
  Program = class
  public
    property Value: Integer public read private write; 
  end;

```

If the real-world case is more complex than this, then you could presumably still achieve the desired result by provisioning a **public** _read-only_ property to read `fValue` and use that property in your public inlined method:

```
type
  Program = class
  private
    fValue: Integer;
  public
    property Value: Integer read fValue;

    method SomethingThatUsesValue; inline;
    begin
       var twiceTheValue := Value * 2;
    end;
  end;
```

---

<div class="post-metadata">

### Author: ![uffe](https://talk.remobjects.com/user_avatar/talk.remobjects.com/uffe/32/1438_2.png) [@uffe](https://talk.remobjects.com/u/uffe)
#### Post date: [March 12, 2017, 3:53pm UTC](https://talk.remobjects.com/t/inconsistent-visibility-with-an-inlined-method/12399/4 "2017-03-12T15:53:44Z")

</div>

After having run into one more issue related to an inlined method, we have decided to add {$IFNDEF oxygene} around all inline statements in our source code. More or less every time Oxygene has been updated with a new major release we have had problems with inlined methods. Stuff that works in Delphi and also in the previous version of oxygene.

Maxim and I are both working on the same code. I do the Delphi part, then he adapts it to Oxygene where needed.
