Initing sublacss with superclass method

Riccardo Mottola <[email protected]> Fri, 11 Jul 2025 13:17:25 +0000
Newsgroups gmane.comp.lib.gnustep.devel
Message-ID <[email protected]>
Hi,

In Grr there is this code:

=C2=A0=C2=A0=C2=A0 wsAndTagClosing =3D [NSMutableCharacterSet
characterSetWithCharactersInString: @"/>"];

Clang warns me with:

NSString+TolerantHTML.m:109:21: warning: incompatible pointer types
assigning to 'NSMutableCharacterSet *' from 'NSCharacterSet *'
[-Wincompatible-pointer-types]
=C2=A0 109 |=C2=A0=C2=A0=C2=A0=C2=A0 wsAndTagClosing =3D [NSMutableCharac=
terSet
characterSetWithCharactersInString: @"/>"];

GCC gives a more generic issue about "distinct objective C type".

Now, characterSetWithCharactersInString: is a class method of
NSCharacterSet:

https://www.gnustep.org/resources/documentation/Developer/Base/Reference/=
NSCharacterSet.html#method$NSCharacterSet+characterSetWithCharactersInStr=
ing$

and NSMutableCharacterSet is a subclass of NSCharacterSet

Shouldn't thus the method called on the subclass still return a valid
subclass and not the superclass?

Could it be a header issue? we define it as:
+ (NSCharacterSet*) characterSetWithCharactersInString: (NSString*)aStrin=
g;

maybe it should return instancetype?

Just wondering & asking.

Riccardo