Forum > General
Specialisation doesn't seem to always create a new type
nixbody:
The FPC documentation states that: "Whenever a generic class is specialized, this results in a new, distinct type." (please see https://www.freepascal.org/docs-html/ref/refse57.html). But that doesn't seem to be the case for every specialisation. In a unit specialisations of one generic type with the same type parameter seem to share one generated type.
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---{$MODE OBJFPC}{$H+} type generic TTest<T> = record end; begin WriteLn(IntPtr(TypeInfo(specialize TTest<Integer>))); WriteLn(IntPtr(TypeInfo(specialize TTest<Integer>))); // Same address.end.
Do I misunderstand the documentation and this is supposed behaviour or is it a bug (either in the documentation or in FPC)?
Thank you for your kind answers. :)
Zoran:
If it behaves so, then I'd say it is a bug -- it doesn't behave as documented.
Please report. Let the fpc developers decide whether documentation or implementation should be changed.
PascalDragon:
--- Quote from: nixbody on February 06, 2025, 08:44:52 pm ---The FPC documentation states that: "Whenever a generic class is specialized, this results in a new, distinct type." (please see https://www.freepascal.org/docs-html/ref/refse57.html). But that doesn't seem to be the case for every specialisation. In a unit specialisations of one generic type with the same type parameter seem to share one generated type.
--- End quote ---
What the documentation should mean is that each specialization with different types for the parameters results in a distinct type. For the same types it's an implementation detail whether they are the same or not and this may change with future versions or the optimizations used.
nixbody:
Ok, thank you for clarification. I should have known better that these things are usually implementation details. From the language of the documentation it seemed that I can rely on every specialisation to produce a new type which would be awesome for my use case, but it is what it is and I get it. Should I report it then? I mean the documentation.
PascalDragon:
--- Quote from: nixbody on February 06, 2025, 10:23:06 pm ---Should I report it than? I mean the documentation.
--- End quote ---
Yes, please report it (for the documentation subproject). You can quote my post for a potential improvement of the documentation.
Navigation
[0] Message Index
[#] Next page