www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Error: no property "someFont" for type int

reply Marco de Wild <admin localhost.com> writes:
I'm trying to build a small manga reader application (because why 
search the internet if you can build it yourself), using DSFML. 
However, I'm getting a weird compilation error that I can't 
decrypt.

In directory.d:
using style;
(...)
_text = new Text;
with(_text)
{
     setFont(Style.DirectoryFont);


In style.d:
module style;
(...)
public static class Style
{
     private static Font _font;
     public static Font DirectoryFont()
     {
         if(!(_font is null)) return _font;
         _font = new Font;
         Load(_font); // Helper function that loads the font into 
_font
         return _font;
     }
}

I'm getting the error message that the compiler can't find
source/directory.d(...) : Error: no property 'DirectoryFont' for 
type 'int'.
When I change the line to actually contain the (iirc optional) 
brackets, the type changes to 'Style'. Am I missing something 
with regards to static classes and members in D?
Thanks in advance.
Nov 10 2015
parent reply Mike Parker <aldacron gmail.com> writes:
On Wednesday, 11 November 2015 at 06:37:44 UTC, Marco de Wild 
wrote:

 In directory.d:
 using style;
This is not D. It should be giving you a compiler error. How are you compiling? Or did you type 'using' in the post by mistake? Anyway, what you want is: import style;
 In style.d:
 module style;
 (...)
 public static class Style
 {
'static class' has no meaning in module scope, only for inner classes. It's not the cause of your problem though.
 I'm getting the error message that the compiler can't find
 source/directory.d(...) : Error: no property 'DirectoryFont' 
 for type 'int'.
 When I change the line to actually contain the (iirc optional) 
 brackets, the type changes to 'Style'. Am I missing something 
 with regards to static classes and members in D?
 Thanks in advance.
The error is likley because of a symbol conflict. Assuming that Text is from the module dsfml.text.graphics, it has an enum type named Style. There's an unfortunate issue in D that allows both of the following to compile: auto e1 = Text.Style.Regular; _text.Style.Regular; The latter should not be allowed, IMO, but it is what it is. So in your case, accessing your Style class in the scope of with(_text) is causing the compiler to find _text.Style. The solution is to use the FQN (Fully Qualified Name) on your Style inside the with, i.e. style.Style, or to drop the with altogether.
Nov 10 2015
next sibling parent Mike Parker <aldacron gmail.com> writes:
On Wednesday, 11 November 2015 at 07:46:31 UTC, Mike Parker wrote:

 Text is from the module dsfml.text.graphics, it has an enum
And of course, I meant dsfml.graphics.text.
Nov 10 2015
prev sibling parent Marco de Wild <admin localhost.com> writes:
 This is not D. It should be giving you a compiler error. How 
 are you compiling? Or did you type 'using' in the post by 
 mistake? Anyway, what you want is:

 import style;
I indeed made a typo while typing the post (and also on various occasions while writing the program, but compiler errors fixed that). That's what you get for using C# at work.
 In style.d:
 module style;
 (...)
 public static class Style
 {
'static class' has no meaning in module scope, only for inner classes. It's not the cause of your problem though.
Thanks for the heads up :) I figured it was about time to dust my D-skills.
 The error is likley because of a symbol conflict. Assuming that 
 Text is from the module dsfml.text.graphics, it has an enum 
 type named Style. There's an unfortunate issue in D that allows 
 both of the following to compile:

 auto e1 = Text.Style.Regular;
 _text.Style.Regular;

 The latter should not be allowed, IMO, but it is what it is. So 
 in your case, accessing your Style class in the scope of 
 with(_text) is causing the compiler to find _text.Style. The 
 solution is to use the FQN (Fully Qualified Name) on your Style 
 inside the with, i.e. style.Style, or to drop the with 
 altogether.
Dropping the with worked like a charm, thanks a lot for the fast reply!
Nov 11 2015