Page MenuHomeFeedback Tracker

Enscript constructor weirdness.
Closed, ResolvedPublic

Description

class TypeA {}
class TypeB : TypeA {}
class TypeC : TypeB {}

class ClassA {
	void ClassA(TypeA typeA) {}
}
class ClassB : ClassA {
	void ClassB(TypeB typeB) {}
}
class ClassC : ClassB {
	void ClassC(TypeC typeC) {
		TypeC typeC2 = (TypeC)typeA;
	}
}
ClassC classC = new ClassC(new TypeC());
TypeC typeC2 = (TypeC)typeA; // yes the ident is typeA which is clearly not defined in that ctor, i explain this later.

For the line above, an error is thrown that this is "unsafe down-casting", which is not true, cast is being done between the same exact types from static point of view. If we went with the idea that Enscript does not support constructor overloading, then it means that the above code should not compile. At first, I thought that only the top level "base" constructor (TypeA) is put into consideration, then I realised that it's not the case, i.e.,

ClassC classC = new ClassC(new TypeA());

does not compile, so okay, it expects 'TypeC' as declared in the constructor of 'ClassC', but then the signature of ClassC's constructor is actually the signature of ClassA's, if you look at the code, even though the parameter 1 is 'TypeC typeC', the compiler sees it as 'TypeA typeA' (yes even the identifier).

class ClassC : ClassB {
	void ClassC(TypeC typeC) {
		TypeC typeC2 = (TypeC)typeA;
	}
}

'typeA' is clearly undefined in this constructor and 'typeC' is defined being 'TypeC', however, that's not the case, the signature of this ctor according to the compiler is actually

void ClassC(TypeA typeA);

You can look at this in many different ways, in any case this is clearly a bug, bug as in, Enscript requires exact ctors in all the derived classes but when attempted otherwise, no error is thrown.

Details

Severity
None
Resolution
Open
Reproducibility
Always
Operating System
Windows 10 x64
Category
General

Event Timeline

sharp1337 updated the task description. (Show Details)
sharp1337 updated the task description. (Show Details)Sep 15 2022, 9:40 AM
Geez changed the task status from New to Assigned.Sep 20 2022, 12:57 PM
Geez closed this task as Resolved.Apr 26 2023, 2:30 PM
Geez claimed this task.
Geez added a subscriber: Geez.

Hello Sharp1337.
This is going to be fixed in one of future updates.