mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-17 19:29:18 +02:00
fcl-passrc: mode objfpc: error on specialize without keyword
git-svn-id: trunk@42951 -
This commit is contained in:
parent
ccc57389cf
commit
349d7845e8
@ -1570,7 +1570,8 @@ begin
|
|||||||
ParseExcSyntaxError;
|
ParseExcSyntaxError;
|
||||||
UnGetToken;
|
UnGetToken;
|
||||||
end
|
end
|
||||||
else if (CurToken = tkLessThan) then // A = B<t>;
|
else if (CurToken = tkLessThan)
|
||||||
|
and (MustBeSpecialize or (msDelphi in CurrentModeswitches)) then // A = B<t>;
|
||||||
begin
|
begin
|
||||||
Result:=ParseSpecializeType(Parent,TypeName,Name,Expr);
|
Result:=ParseSpecializeType(Parent,TypeName,Name,Expr);
|
||||||
ok:=true;
|
ok:=true;
|
||||||
|
@ -97,7 +97,7 @@ begin
|
|||||||
' b : T;',
|
' b : T;',
|
||||||
'end;',
|
'end;',
|
||||||
'Generic TBird<T: class> = class',
|
'Generic TBird<T: class> = class',
|
||||||
' c : TBird<T>;',
|
' c : specialize TBird<T>;',
|
||||||
'end;',
|
'end;',
|
||||||
'Generic TEagle<T: record> = class',
|
'Generic TEagle<T: record> = class',
|
||||||
'end;',
|
'end;',
|
||||||
@ -116,11 +116,11 @@ begin
|
|||||||
'TBird = class(TInterfacedObject,TIntfA,TIntfB) end;',
|
'TBird = class(TInterfacedObject,TIntfA,TIntfB) end;',
|
||||||
'Generic TAnt<T: TIntfA, TIntfB> = class',
|
'Generic TAnt<T: TIntfA, TIntfB> = class',
|
||||||
' b: T;',
|
' b: T;',
|
||||||
' c: TAnt<T>;',
|
' c: specialize TAnt<T>;',
|
||||||
'end;',
|
'end;',
|
||||||
'Generic TFly<T: TIntfA, TIntfB; S> = class',
|
'Generic TFly<T: TIntfA, TIntfB; S> = class',
|
||||||
' b: S;',
|
' b: S;',
|
||||||
' c: TFly<T>;',
|
' c: specialize TFly<T>;',
|
||||||
'end;',
|
'end;',
|
||||||
'']);
|
'']);
|
||||||
ParseDeclarations;
|
ParseDeclarations;
|
||||||
@ -148,6 +148,7 @@ end;
|
|||||||
|
|
||||||
procedure TTestGenerics.TestSpecializationDelphi;
|
procedure TTestGenerics.TestSpecializationDelphi;
|
||||||
begin
|
begin
|
||||||
|
Add('{$mode delphi}');
|
||||||
ParseType('TFPGList<integer>',TPasSpecializeType,'');
|
ParseType('TFPGList<integer>',TPasSpecializeType,'');
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -147,7 +147,7 @@ begin
|
|||||||
StartProgram(false);
|
StartProgram(false);
|
||||||
Add([
|
Add([
|
||||||
'type generic TBird<T> = record end;',
|
'type generic TBird<T> = record end;',
|
||||||
'var b: TBird<word, byte>;',
|
'var b: specialize TBird<word, byte>;',
|
||||||
'begin',
|
'begin',
|
||||||
'']);
|
'']);
|
||||||
CheckResolverException('identifier not found "TBird<,>"',
|
CheckResolverException('identifier not found "TBird<,>"',
|
||||||
@ -523,9 +523,9 @@ begin
|
|||||||
' for i in m do ;',
|
' for i in m do ;',
|
||||||
'end;',
|
'end;',
|
||||||
'var',
|
'var',
|
||||||
' a: TAnt<word>;',
|
' a: specialize TAnt<word>;',
|
||||||
' w: word;',
|
' w: word;',
|
||||||
' b: TBird<word,specialize TAnt<word>>;',
|
' b: specialize TBird<word,specialize TAnt<word>>;',
|
||||||
'begin',
|
'begin',
|
||||||
' for w in a do ;',
|
' for w in a do ;',
|
||||||
' for w in b.m do ;',
|
' for w in b.m do ;',
|
||||||
@ -800,12 +800,12 @@ begin
|
|||||||
' generic TAnt<T> = class;',
|
' generic TAnt<T> = class;',
|
||||||
' generic TFish<U> = class',
|
' generic TFish<U> = class',
|
||||||
' private type AliasU = U;',
|
' private type AliasU = U;',
|
||||||
' var a: TAnt<AliasU>;',
|
' var a: specialize TAnt<AliasU>;',
|
||||||
' Size: AliasU;',
|
' Size: AliasU;',
|
||||||
' end;',
|
' end;',
|
||||||
' generic TAnt<T> = class',
|
' generic TAnt<T> = class',
|
||||||
' private type AliasT = T;',
|
' private type AliasT = T;',
|
||||||
' var f: TFish<AliasT>;',
|
' var f: specialize TFish<AliasT>;',
|
||||||
' Speed: AliasT;',
|
' Speed: AliasT;',
|
||||||
' end;',
|
' end;',
|
||||||
'var',
|
'var',
|
||||||
@ -991,7 +991,7 @@ begin
|
|||||||
' TObject = class end;',
|
' TObject = class end;',
|
||||||
' generic TBird<T> = class',
|
' generic TBird<T> = class',
|
||||||
' e: T;',
|
' e: T;',
|
||||||
' v: TBird<boolean>;',
|
' v: specialize TBird<boolean>;',
|
||||||
' end;',
|
' end;',
|
||||||
'var',
|
'var',
|
||||||
' b: specialize TBird<word>;',
|
' b: specialize TBird<word>;',
|
||||||
@ -1606,8 +1606,8 @@ begin
|
|||||||
' except',
|
' except',
|
||||||
' on Exception do ;',
|
' on Exception do ;',
|
||||||
' on E: Exception do ;',
|
' on E: Exception do ;',
|
||||||
' on E: EMsg<boolean> do E.Msg:=true;',
|
' on E: specialize EMsg<boolean> do E.Msg:=true;',
|
||||||
' on E: EMsg<T> do E.Msg:=1;',
|
' on E: specialize EMsg<T> do E.Msg:=1;',
|
||||||
' end;',
|
' end;',
|
||||||
'end;',
|
'end;',
|
||||||
'var',
|
'var',
|
||||||
|
@ -6,7 +6,7 @@ interface
|
|||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, SysUtils, fpcunit, testregistry,
|
Classes, SysUtils, fpcunit, testregistry,
|
||||||
TCModules;
|
TCModules, FPPas2Js;
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
||||||
@ -22,6 +22,7 @@ type
|
|||||||
Procedure TestGen_Class_EmptyMethod;
|
Procedure TestGen_Class_EmptyMethod;
|
||||||
Procedure TestGen_Class_TList;
|
Procedure TestGen_Class_TList;
|
||||||
Procedure TestGen_ClassAncestor;
|
Procedure TestGen_ClassAncestor;
|
||||||
|
Procedure TestGen_TypeInfo;
|
||||||
|
|
||||||
// generic external class
|
// generic external class
|
||||||
procedure TestGen_ExtClass_Array;
|
procedure TestGen_ExtClass_Array;
|
||||||
@ -242,6 +243,51 @@ begin
|
|||||||
'']));
|
'']));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TTestGenerics.TestGen_TypeInfo;
|
||||||
|
begin
|
||||||
|
Converter.Options:=Converter.Options-[coNoTypeInfo];
|
||||||
|
StartProgram(false);
|
||||||
|
Add([
|
||||||
|
'type',
|
||||||
|
' TObject = class end;',
|
||||||
|
' generic TBird<T> = class',
|
||||||
|
' published',
|
||||||
|
' m: T;',
|
||||||
|
' end;',
|
||||||
|
' TEagle = specialize TBird<word>;',
|
||||||
|
'var',
|
||||||
|
' b: specialize TBird<word>;',
|
||||||
|
' p: pointer;',
|
||||||
|
'begin',
|
||||||
|
' p:=typeinfo(TEagle);',
|
||||||
|
' p:=typeinfo(b);',
|
||||||
|
'']);
|
||||||
|
ConvertProgram;
|
||||||
|
CheckSource('TestGen_TypeInfo',
|
||||||
|
LinesToStr([ // statements
|
||||||
|
'rtl.createClass($mod, "TObject", null, function () {',
|
||||||
|
' this.$init = function () {',
|
||||||
|
' };',
|
||||||
|
' this.$final = function () {',
|
||||||
|
' };',
|
||||||
|
'});',
|
||||||
|
'rtl.createClass($mod, "TBird$G1", $mod.TObject, function () {',
|
||||||
|
' this.$init = function () {',
|
||||||
|
' $mod.TObject.$init.call(this);',
|
||||||
|
' this.m = 0;',
|
||||||
|
' };',
|
||||||
|
' var $r = this.$rtti;',
|
||||||
|
' $r.addField("m", rtl.word);',
|
||||||
|
'});',
|
||||||
|
'this.b = null;',
|
||||||
|
'this.p = null;',
|
||||||
|
'']),
|
||||||
|
LinesToStr([ // $mod.$main
|
||||||
|
'$mod.p = $mod.$rtti["TBird$G1"];',
|
||||||
|
'$mod.p = $mod.b.$rtti;',
|
||||||
|
'']));
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TTestGenerics.TestGen_ExtClass_Array;
|
procedure TTestGenerics.TestGen_ExtClass_Array;
|
||||||
begin
|
begin
|
||||||
StartProgram(false);
|
StartProgram(false);
|
||||||
@ -314,7 +360,7 @@ begin
|
|||||||
' generic TBird<T> = class',
|
' generic TBird<T> = class',
|
||||||
' end;',
|
' end;',
|
||||||
'constructor TObject.Create; begin end;',
|
'constructor TObject.Create; begin end;',
|
||||||
'var b: TBird<word>;',
|
'var b: specialize TBird<word>;',
|
||||||
'begin',
|
'begin',
|
||||||
' b:=specialize TBird<word>.Create;',
|
' b:=specialize TBird<word>.Create;',
|
||||||
'']);
|
'']);
|
||||||
|
Loading…
Reference in New Issue
Block a user