<div dir="auto"><div><div class="gmail_quote"><div dir="ltr">Am Di., 27. Nov. 2018, 14:00 hat Ryan Joseph <<a href="mailto:ryan@thealchemistguild.com">ryan@thealchemistguild.com</a>> geschrieben:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
<br>
> On Nov 27, 2018, at 5:35 PM, Sven Barth via fpc-pascal <<a href="mailto:fpc-pascal@lists.freepascal.org" target="_blank" rel="noreferrer">fpc-pascal@lists.freepascal.org</a>> wrote:<br>
> <br>
> 1) kSomeDays is a typed const so I get a load node instead of tsetconstnode, which I need to need to know in order to make the name string. See the TODO’s in tgenericparamdef.create.<br>
> <br>
> type<br>
>         TDay = (Mon, Tue, Wed);<br>
>         TDays = set of TDay;<br>
> const<br>
>         kSomeDays:TDays = [Mon, Wed];<br>
> <br>
> <br>
> var<br>
>         d: specialize TMyRecord_Set<integer,kSomeDays>; // this doesn’t work<br>
>         d: specialize TMyRecord_Set<integer,[Mon,Wed]>; // this works because I get a set node<br>
> <br>
> The difference between typed and untyped constants are available everywhere else in the language as well, so I have no qualms (at least for now?) to error out on them. <br>
<br>
You mean reject them? The default behavior is to get a type_e_type_id_expected error. They can be included easily but I don’t know how to get the set from the load node (I think it needs further parsing).<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">We can add a new message that says "type id or untyped constant expected". But if it correctly errors right now, we can leave it be for now. </div><div dir="auto"><br></div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
> <br>
> For sets I believe that this should work however (see here:  <a href="https://freepascal.org/docs-html/current/ref/refse9.html#x21-200002.1" rel="noreferrer noreferrer" target="_blank">https://freepascal.org/docs-html/current/ref/refse9.html#x21-200002.1</a> ):<br>
> <br>
> === code begin ===<br>
> const<br>
>   kSomeDays = [Mon, Wed];<br>
> === code end ===<br>
<br>
Yes, sets work because I get a setnode which I can operate on.<br>
<br>
> <br>
> Did you try with the generic and the specialization in different units and changing only one of the two? Though you might want to check whether tstoreddef.ppuload (or wherever tdef.genericparas is initialized after a unit load) correctly instantiated the tconstsym instances instead of ttypesym ones. It might already work correctly, but better safe than sorry. 😅<br>
<br>
That seems to work. Here is my test:<br>
<br>
========================================<br>
<br>
program gc_ppu;<br>
uses<br>
        gc_types_unit;<br>
<br>
var<br>
        a: TShortIntList;<br>
begin<br>
        a.dothis('hello’);<br>
        GlobalShortIntList.dothis('world');<br>
end.<br>
<br>
========================================<br>
<br>
unit gc_types_unit;<br>
interface<br>
<br>
type<br>
        generic TList<T, const U:integer> = record<br>
                const ID = U;<br>
                public<br>
                        list: array[0..U-1] of T;<br>
                        procedure dothis (msg:string);<br>
        end;<br>
<br>
const<br>
        kShortListLength = 128;<br>
type<br>
        TShortIntList = specialize TList<Shortint,kShortListLength>;<br>
<br>
var<br>
        GlobalShortIntList: TShortIntList;<br>
<br>
implementation<br>
<br>
procedure TList.dothis (msg:string);<br>
begin<br>
        writeln('message:',msg, ' high:', high(ID), ' constsize:', sizeof(ID), ' structsize:', sizeof(self));<br>
end;<br>
<br>
end.<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">You did read the part about the generic and the specialization being located in two different units? 😉</div><div dir="auto"><br></div><div dir="auto">Regards, </div><div dir="auto">Sven </div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"></blockquote></div></div></div>