summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormattias <mattias@3ad0048d-3df7-0310-abae-a5850022a9f2>2020-04-26 19:23:54 +0000
committermattias <mattias@3ad0048d-3df7-0310-abae-a5850022a9f2>2020-04-26 19:23:54 +0000
commit5632f39a7cf6128864d4b177dcf2efd12172356a (patch)
tree6dbe30a3e5196b08441f0641092eabb06a1360bd
parent719bbeab4e68c03efbe5fa7f55d07ccf341554f9 (diff)
downloadfpc-5632f39a7cf6128864d4b177dcf2efd12172356a.tar.gz
fcl-passrc: fixed type helper intdouble/uintdouble
git-svn-id: https://svn.freepascal.org/svn/fpc/trunk@45121 3ad0048d-3df7-0310-abae-a5850022a9f2
-rw-r--r--packages/fcl-passrc/src/pasresolver.pp9
-rw-r--r--packages/pastojs/tests/tcmodules.pas94
2 files changed, 99 insertions, 4 deletions
diff --git a/packages/fcl-passrc/src/pasresolver.pp b/packages/fcl-passrc/src/pasresolver.pp
index 35fcebfe60..13b804b252 100644
--- a/packages/fcl-passrc/src/pasresolver.pp
+++ b/packages/fcl-passrc/src/pasresolver.pp
@@ -431,7 +431,8 @@ const
btArrayRangeTypes = btAllChars+btAllBooleans+btAllInteger;
btAllRanges = btArrayRangeTypes+[btRange];
btAllWithSubType = [btSet, btArrayLit, btArrayOrSet, btRange];
- btAllStandardTypes = [
+ btAllIntrinsicTypes = btAllInteger+btAllStringAndChars+btAllFloats+btAllBooleans;
+ btAllFPCTypes = [
btChar,
{$ifdef FPC_HAS_CPSTRING}
btAnsiChar,
@@ -2080,7 +2081,7 @@ type
// built in types and functions
procedure ClearBuiltInIdentifiers; virtual;
procedure AddObjFPCBuiltInIdentifiers(
- const TheBaseTypes: TResolveBaseTypes = btAllStandardTypes;
+ const TheBaseTypes: TResolveBaseTypes = btAllFPCTypes;
const TheBaseProcs: TResolverBuiltInProcs = bfAllStandardProcs); virtual;
function AddBaseType(const aName: string; Typ: TResolverBaseType): TResElDataBaseType;
function AddCustomBaseType(const aName: string; aClass: TResElDataBaseTypeClass): TPasUnresolvedSymbolRef;
@@ -10435,7 +10436,7 @@ begin
end;
end;
// default: search for type helpers
- if (LeftResolved.BaseType in btAllStandardTypes)
+ if (LeftResolved.BaseType in btAllIntrinsicTypes)
or (LeftResolved.BaseType=btContext)
or (LeftResolved.BaseType=btCustom) then
begin
@@ -22038,7 +22039,7 @@ begin
if LoType=nil then
RaiseMsg(20170216152004,nExprTypeMustBeClassOrRecordTypeGot,sExprTypeMustBeClassOrRecordTypeGot,
[BaseTypeNames[ExprResolved.BaseType]],ErrorEl);
- if (ExprResolved.BaseType in btAllStandardTypes) then
+ if (ExprResolved.BaseType in btAllIntrinsicTypes) then
// ok
else if (ExprResolved.BaseType=btContext) then
// ok
diff --git a/packages/pastojs/tests/tcmodules.pas b/packages/pastojs/tests/tcmodules.pas
index be2b4dc428..b8aec665fa 100644
--- a/packages/pastojs/tests/tcmodules.pas
+++ b/packages/pastojs/tests/tcmodules.pas
@@ -702,6 +702,7 @@ type
Procedure TestTypeHelper_Constructor;
Procedure TestTypeHelper_Word;
Procedure TestTypeHelper_Double;
+ Procedure TestTypeHelper_NativeInt;
Procedure TestTypeHelper_StringChar;
Procedure TestTypeHelper_JSValue;
Procedure TestTypeHelper_Array;
@@ -24090,6 +24091,99 @@ begin
'']));
end;
+procedure TTestModule.TestTypeHelper_NativeInt;
+begin
+ StartProgram(false);
+ Add([
+ '{$modeswitch typehelpers}',
+ 'type',
+ ' MaxInt = type nativeint;',
+ ' THelperI = type helper for MaxInt',
+ ' function ToStr: String;',
+ ' end;',
+ ' MaxUInt = type nativeuint;',
+ ' THelperU = type helper for MaxUInt',
+ ' function ToStr: String;',
+ ' end;',
+ 'function THelperI.ToStr: String;',
+ 'begin',
+ ' Result:=str(Self);',
+ 'end;',
+ 'function THelperU.ToStr: String;',
+ 'begin',
+ ' Result:=str(Self);',
+ 'end;',
+ 'procedure DoIt(s: string);',
+ 'begin',
+ 'end;',
+ 'var i: MaxInt;',
+ 'begin',
+ ' DoIt(i.toStr);',
+ ' DoIt(i.toStr());',
+ ' (i*i).toStr;',
+ ' DoIt((i*i).toStr);',
+ '']);
+ ConvertProgram;
+ CheckSource('TestTypeHelper_NativeInt',
+ LinesToStr([ // statements
+ 'rtl.createHelper($mod, "THelperI", null, function () {',
+ ' this.ToStr = function () {',
+ ' var Result = "";',
+ ' Result = "" + this.get();',
+ ' return Result;',
+ ' };',
+ '});',
+ 'rtl.createHelper($mod, "THelperU", null, function () {',
+ ' this.ToStr = function () {',
+ ' var Result = "";',
+ ' Result = "" + this.get();',
+ ' return Result;',
+ ' };',
+ '});',
+ 'this.DoIt = function (s) {',
+ '};',
+ 'this.i = 0;',
+ '']),
+ LinesToStr([ // $mod.$main
+ '$mod.DoIt($mod.THelperI.ToStr.call({',
+ ' p: $mod,',
+ ' get: function () {',
+ ' return this.p.i;',
+ ' },',
+ ' set: function (v) {',
+ ' this.p.i = v;',
+ ' }',
+ '}));',
+ '$mod.DoIt($mod.THelperI.ToStr.call({',
+ ' p: $mod,',
+ ' get: function () {',
+ ' return this.p.i;',
+ ' },',
+ ' set: function (v) {',
+ ' this.p.i = v;',
+ ' }',
+ '}));',
+ '$mod.THelperI.ToStr.call({',
+ ' a: $mod.i * $mod.i,',
+ ' get: function () {',
+ ' return this.a;',
+ ' },',
+ ' set: function (v) {',
+ ' rtl.raiseE("EPropReadOnly");',
+ ' }',
+ '});',
+ '$mod.DoIt($mod.THelperI.ToStr.call({',
+ ' a: $mod.i * $mod.i,',
+ ' get: function () {',
+ ' return this.a;',
+ ' },',
+ ' set: function (v) {',
+ ' rtl.raiseE("EPropReadOnly");',
+ ' }',
+ '}));',
+ '']));
+end;
+
procedure TTestModule.TestTypeHelper_StringChar;
begin
StartProgram(false);