View Issue Details

IDProjectCategoryView StatusLast Update
0000647LDMud 3.5LPC Compiler/Preprocessorpublic2021-04-07 00:04
Reporter_xtian_ Assigned To 
Status resolvedResolutionfixed 
Summary0000647: struct types in arguments not checked at compile time; polymorphism request
DescriptionStruct (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).
TagsNo tags attached.



2009-06-01 08:11

administrator   ~0001178

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.


2009-06-01 09:06

manager   ~0001182

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.


2021-04-07 00:04

manager   ~0002565

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.

Issue History

Date Modified Username Field Change
2009-06-01 07:31 _xtian_ New Issue
2009-06-01 07:37 zesstra Project LDMud => LDMud 3.5
2009-06-01 08:11 zesstra Note Added: 0001178
2009-06-01 09:06 Gnomi Note Added: 0001182
2021-04-07 00:04 Gnomi Assigned To => Gnomi
2021-04-07 00:04 Gnomi Status new => closed
2021-04-07 00:04 Gnomi Resolution open => fixed
2021-04-07 00:04 Gnomi Note Added: 0002565
2021-04-07 00:04 Gnomi Assigned To Gnomi =>
2021-04-07 00:04 Gnomi Status closed => resolved