Browse Source

pastojs: show jsvalue ninstead of custom in incompatible type messages

git-svn-id: trunk@35854 -
Mattias Gaertner 8 years ago
parent
commit
6d2dbb564c
2 changed files with 28 additions and 1 deletions
  1. 11 0
      packages/pastojs/src/fppas2js.pp
  2. 17 1
      packages/pastojs/tests/tcmodules.pas

+ 11 - 0
packages/pastojs/src/fppas2js.pp

@@ -894,6 +894,8 @@ type
     function CreateElementData(DataClass: TPas2JsElementDataClass;
       El: TPasElement): TPas2JsElementData; virtual;
     // utility
+    function GetBaseDescription(const R: TPasResolverResult; AddPath: boolean=
+      false): string; override;
     function HasTypeInfo(El: TPasType): boolean; override;
   end;
 
@@ -2918,6 +2920,15 @@ begin
   AddElementData(Result);
 end;
 
+function TPas2JSResolver.GetBaseDescription(const R: TPasResolverResult;
+  AddPath: boolean): string;
+begin
+  if (R.BaseType=btCustom) and (R.TypeEl.CustomData is TResElDataPas2JSBaseType) then
+    Result:=Pas2jsBaseTypeNames[TResElDataPas2JSBaseType(R.TypeEl.CustomData).JSBaseType]
+  else
+    Result:=inherited GetBaseDescription(R, AddPath);
+end;
+
 function TPas2JSResolver.HasTypeInfo(El: TPasType): boolean;
 begin
   Result:=inherited HasTypeInfo(El);

+ 17 - 1
packages/pastojs/tests/tcmodules.pas

@@ -439,6 +439,7 @@ type
     Procedure TestJSValue_FuncResultType;
     Procedure TestJSValue_ProcType_Assign;
     Procedure TestJSValue_ProcType_Equal;
+    Procedure TestJSValue_AssignToPointerFail;
 
     // RTTI
     Procedure TestRTTI_ProcType;
@@ -774,7 +775,7 @@ begin
     Fail('TTestModuleConverter.AddModule: file "'+aFilename+'" already exists');
   Result:=TTestEnginePasResolver.Create;
   Result.Filename:=aFilename;
-  Result.AddObjFPCBuiltInIdentifiers(btAllJSBaseTypes,bfAllPas2jsBaseProcs);
+  Result.AddObjFPCBuiltInIdentifiers(btAllJSBaseTypes,bfAllJSBaseProcs);
   Result.OnFindUnit:=@OnPasResolverFindUnit;
   FModules.Add(Result);
 end;
@@ -11431,6 +11432,21 @@ begin
     '']));
 end;
 
+procedure TTestModule.TestJSValue_AssignToPointerFail;
+begin
+  StartProgram(false);
+  Add([
+  'var',
+  '  v: JSValue;',
+  '  p: Pointer;',
+  'begin',
+  '  p:=v;',
+  '']);
+  SetExpectedPasResolverError('Incompatible types: got "JSValue" expected "Pointer"',
+    nIncompatibleTypesGotExpected);
+  ConvertProgram;
+end;
+
 procedure TTestModule.TestRTTI_ProcType;
 begin
   Converter.Options:=Converter.Options-[coNoTypeInfo];