View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0000647 | LDMud 3.5 | LPC Compiler/Preprocessor | public | 2009-06-01 05:31 | 2021-04-06 22:04 |
Reporter | _xtian_ | Assigned To | |||
Priority | normal | Severity | minor | Reproducibility | always |
Status | resolved | Resolution | fixed | ||
Summary | 0000647: struct types in arguments not checked at compile time; polymorphism request | ||||
Description | Struct (template) type does not seem to be checked in function arguments at compile time. This actually compiles: #pragma strict_types #pragma save_types struct a { int j; }; struct b { int i; }; void fun(struct a bla) // expects a { printf("%O\n", bla); } void create() { fun( () ); // this compiles with b. Should be (<a>) } Now, this should throw an error when compiling. (note: if you access an non-existing member of "bla" at runtime, this will properly cause an error) | ||||
Additional Information | ... BUT: I would like to make a strong case for polymorphism in structs as arguments for functions. This would mean that the modified above case: struct b (a) { // b now inherits from a int i; }; ... and the rest of the above example, would then again compile correctly. void fun(struct a bla); void create() { fun( () ); // this now works because b inherits a } So this is a request for adding compile-time checks of struct-type into function call arguments, but also allowing arguments who are "related" to those expected. Good reasons for polymorphism in this place: - it should be fairly simple to implement (although Im not a driver-hacker, I dont know exactly what this needs) - it greatly enhances the possibilities to work with structs as you can define your own data types (different structs) and achieve some type-safety with them while using some sort of generic function like in the example. - I need it ;) ... I _really_ need it. - since until now there were no type-checks at compile-time at all, there could be users who are using this possibility of passing different struct-types as arguments. This would be a way of keeping those mechanics (albeit more elegantly). | ||||
Tags | No tags attached. | ||||
|
Huh. All struct values have internally the LPC type T_STRUCT, no matter what struct it actually is. And the compiler just looks at the primary type tag. I am not sure that this is a really simple thing to change. |
|
The fulltype_s structure already has the information about which structure T_STRUCT refers to, it's already checked for assignments (struct a x = (); is not allowed), but not for function calls. |
|
I checked it with LDMud 3.6.4 and the given code throws 'Bad type for argument 1 of fun (struct a vs struct b)'. I think the check works since LDMud 3.5.0. |
Date Modified | Username | Field | Change |
---|---|---|---|
2009-06-01 05:31 | _xtian_ | New Issue | |
2009-06-01 05:37 | zesstra | Project | LDMud => LDMud 3.5 |
2009-06-01 06:11 | zesstra | Note Added: 0001178 | |
2009-06-01 07:06 | Gnomi | Note Added: 0001182 | |
2021-04-06 22:04 | Gnomi | Assigned To | => Gnomi |
2021-04-06 22:04 | Gnomi | Status | new => closed |
2021-04-06 22:04 | Gnomi | Resolution | open => fixed |
2021-04-06 22:04 | Gnomi | Note Added: 0002565 | |
2021-04-06 22:04 | Gnomi | Assigned To | Gnomi => |
2021-04-06 22:04 | Gnomi | Status | closed => resolved |