diff options
| author | florian <florian@3ad0048d-3df7-0310-abae-a5850022a9f2> | 2010-04-21 20:19:18 +0000 |
|---|---|---|
| committer | florian <florian@3ad0048d-3df7-0310-abae-a5850022a9f2> | 2010-04-21 20:19:18 +0000 |
| commit | 2cddaa63066d1bd9c7c9012f3acbb4afb91fdbcd (patch) | |
| tree | 03e2c4c3ac26faa147e8b1cfeac2ebaa0af3f090 | |
| parent | 8f79ddb0624939e1f1ce0acaf136057e731b2635 (diff) | |
| download | fpc-2cddaa63066d1bd9c7c9012f3acbb4afb91fdbcd.tar.gz | |
* handle usage of generics type as class type correctly, resolves #16065
git-svn-id: http://svn.freepascal.org/svn/fpc/trunk@15157 3ad0048d-3df7-0310-abae-a5850022a9f2
| -rw-r--r-- | compiler/nmem.pas | 12 | ||||
| -rw-r--r-- | tests/webtbs/tw16065.pp | 26 |
2 files changed, 37 insertions, 1 deletions
diff --git a/compiler/nmem.pas b/compiler/nmem.pas index 8d45282e96..70ab0c0f00 100644 --- a/compiler/nmem.pas +++ b/compiler/nmem.pas @@ -159,7 +159,17 @@ implementation classrefdef : resultdef:=left.resultdef; objectdef : - resultdef:=tclassrefdef.create(left.resultdef); + { access to the classtype while specializing? } + if (df_generic in left.resultdef.defoptions) and + assigned(current_objectdef.genericdef) then + begin + if current_objectdef.genericdef=left.resultdef then + resultdef:=tclassrefdef.create(current_objectdef) + else + message(parser_e_cant_create_generics_of_this_type); + end + else + resultdef:=tclassrefdef.create(left.resultdef); else Message(parser_e_pointer_to_class_expected); end; diff --git a/tests/webtbs/tw16065.pp b/tests/webtbs/tw16065.pp new file mode 100644 index 0000000000..38f1f7e6c8 --- /dev/null +++ b/tests/webtbs/tw16065.pp @@ -0,0 +1,26 @@ +{$mode objfpc} + +type + generic TGen<_T> = class + public + function Check(ASource: TObject): Boolean; + end; + + TSpec = specialize TGen<Integer>; + +function TGen.Check(ASource: TObject): Boolean; +begin + Result := (ASource is TGen) // this line breaks the compiler... + and (ASource is ClassType); // ...it should be equivelent to this line +end; + +var + f: TSpec; + o: TObject; +begin + f := TSpec.Create; + o := TObject.Create; + if not(f.Check(f)) or f.Check(o) then + halt(1); + writeln('ok'); +end. |
