View Issue Details

IDProjectCategoryView StatusLast Update
0037624pas2jsrtlpublic2020-09-28 20:11
ReporterHighball Assigned ToMattias Gaertner  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Summary0037624: uncaught A/V with generic method and constraint
Descriptionwhen creating a class with a generic method as well as a constraint the following exception occurs when attempting to compile
Fatal: bug: uncaught EAccessViolation: Access violation

without the constraint, the compilation works as expected
Steps To Reproduceexample method attached in zip project
Additional Informationa method like this --> function IsType<T : IInterface> : Boolean;
TagsNo tags attached.
Fixed in Revision46902.
Attached Files

Activities

Highball

2020-08-22 23:52

reporter  

generic-constraint.zip (5,070 bytes)

Highball

2020-08-23 00:03

reporter   ~0125086

I don't know if this is the same issue, but testing further, the same exception occurs *without* the constraint, but when returning an interface as the function result

this method does not compile
function IsType<T> : IInterface;

this method will
function IsType<T> : Boolean;

henrique

2020-08-26 16:23

reporter   ~0125136

It's happen to me too!

Highball

2020-08-29 23:26

reporter   ~0125209

just noticed I categorized this bug incorrectly, it should be "compiler" not "rtl" (but I don't know how to adjust... and not sure it's that big of a deal)

henrique

2020-09-02 19:33

reporter   ~0125300

I've attach a fix for this problem. But it creates a new problem in checking interface types, if you pass a parameter class, everything works.
Access violation.patch (1,570 bytes)   
From c13c1a1024754213381ff3e349368540928e9b79 Mon Sep 17 00:00:00 2001
From: Henrique Gottardi Werlang <henriquewerlang@hotmail.com>
Date: Wed, 2 Sep 2020 14:09:38 -0300
Subject: [PATCH] Access violation in generic interface.

---
 packages/fcl-passrc/src/pasresolver.pp | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/packages/fcl-passrc/src/pasresolver.pp b/packages/fcl-passrc/src/pasresolver.pp
index d1b41b0bef..e318f78e87 100644
--- a/packages/fcl-passrc/src/pasresolver.pp
+++ b/packages/fcl-passrc/src/pasresolver.pp
@@ -6628,11 +6628,14 @@ begin
             end;
           okInterface:
             begin
-            // there can be multiple interfacetype constraint
-            if not (LastType is TPasClassType) then
-              RaiseCannotBeTogether(20190720211236,LastType.Name,MemberType.Name);
-            if TPasClassType(LastType).ObjKind<>okInterface then
-              RaiseCannotBeTogether(20190720211304,LastType.Name,MemberType.Name);
+            if Assigned(LastType) then
+              begin
+              // there can be multiple interfacetype constraint
+              if not (LastType is TPasClassType) then
+                RaiseCannotBeTogether(20190720211236,LastType.Name,MemberType.Name);
+              if TPasClassType(LastType).ObjKind<>okInterface then
+                RaiseCannotBeTogether(20190720211304,LastType.Name,MemberType.Name);
+              end;
             end
           else
             RaiseXIsNotAValidConstraint(20190720210919,MemberType.Name);
-- 
2.28.0.windows.1

Access violation.patch (1,570 bytes)   

henrique

2020-09-09 13:28

reporter   ~0125448

Someone can check this implementation of me?

Highball

2020-09-13 18:44

reporter   ~0125527

Any update on reviewing the proposed fix? Would be handy to be able to do this since I pretty much exclusively use interfaces and it would simplify my web framework I'm building

Mattias Gaertner

2020-09-20 01:42

manager   ~0125648

Thanks for the patch.

Highball

2020-09-20 03:17

reporter   ~0125649

Thanks guys

Highball

2020-09-27 23:35

reporter   ~0125912

So I don't believe this was resolved. I pulled trunk today using fpcupdeluxe and then ran make all. when I test my sample project and attempt to compile, I get the same access violation error as initially reported.

Mattias Gaertner

2020-09-28 11:54

manager   ~0125920

The example generic-constraint.zip gives compile error:
Project1.pas(25,33) Error: Implementations must not repeat constraints

Removing the implementation constraint let it compile.

Maybe you have a different sample project?

Highball

2020-09-28 15:44

reporter   ~0125925

Sorry Matthias, I'm still seeing the AV after fetching trunk and then using the generic-constraint project in the first comment. I also tried removing the implementation constraint but still got the AV as well. I pulled using fpcupdeluxe and installing the pas2js module, and then "make all". Is there something different I should try in my process?

Mattias Gaertner

2020-09-28 16:02

manager   ~0125926

Do you have local modifications in your pas2js svn?

Can you create a stacktrace of the AV?

Highball

2020-09-28 17:52

reporter   ~0125933

No I do not have any local mods, and since it's a compile time exception, what would be the best way to create the stack trace?
here's all the messages that print in the messages window,

Compile Project, OS: browser, CPU: ecmascript5, Target: Project1.js: Exit code 1, Errors: 2, Warnings: 1
sysutils.pas(1086,14) Warning: Symbol "Single" is not implemented
Fatal: bug: uncaught EAccessViolation: Access violation
Fatal: EAccessViolation: Access violation

Mattias Gaertner

2020-09-28 19:21

manager   ~0125937

How to create a stacktrace:
https://wiki.freepascal.org/Creating_a_Backtrace_with_GDB

Highball

2020-09-28 20:07

reporter   ~0125938

Last edited: 2020-09-28 20:10

View 2 revisions

So I figured out what I needed to do, but I'm not sure why I had to do it. when trying to setup gdb for the backtrace on pas2js.exe I tried just compiling from command line, and received more verbose messages on the console than I did from within lazarus, and I noticed the version of my compiler was dated a month ago (last time I built using make all). For a test I deleted the bin folder and re-ran make all, then compiled my test project successfully. I also introduced the implementation constraint and did indeed re-create the "Implementation must not repeat constraints" exception.

tldr; bug is fixed, thanks again and I'm not sure why a make all didn't re-compile pas2js compiler

edit:
running make cleanall then a make all did the trick

Issue History

Date Modified Username Field Change
2020-08-22 23:52 Highball New Issue
2020-08-22 23:52 Highball File Added: generic-constraint.zip
2020-08-23 00:03 Highball Note Added: 0125086
2020-08-26 16:23 henrique Note Added: 0125136
2020-08-29 23:26 Highball Note Added: 0125209
2020-09-02 19:33 henrique Note Added: 0125300
2020-09-02 19:33 henrique File Added: Access violation.patch
2020-09-09 13:28 henrique Note Added: 0125448
2020-09-13 18:44 Highball Note Added: 0125527
2020-09-16 23:50 Michael Van Canneyt Assigned To => Mattias Gaertner
2020-09-16 23:50 Michael Van Canneyt Status new => assigned
2020-09-20 01:42 Mattias Gaertner Status assigned => resolved
2020-09-20 01:42 Mattias Gaertner Resolution open => fixed
2020-09-20 01:42 Mattias Gaertner Fixed in Revision => 46902.
2020-09-20 01:42 Mattias Gaertner Note Added: 0125648
2020-09-20 03:17 Highball Note Added: 0125649
2020-09-27 23:35 Highball Status resolved => feedback
2020-09-27 23:35 Highball Resolution fixed => open
2020-09-27 23:35 Highball Note Added: 0125912
2020-09-28 11:54 Mattias Gaertner Note Added: 0125920
2020-09-28 15:44 Highball Note Added: 0125925
2020-09-28 15:44 Highball Status feedback => assigned
2020-09-28 16:02 Mattias Gaertner Note Added: 0125926
2020-09-28 17:52 Highball Note Added: 0125933
2020-09-28 19:21 Mattias Gaertner Note Added: 0125937
2020-09-28 20:07 Highball Note Added: 0125938
2020-09-28 20:10 Highball Note Edited: 0125938 View Revisions
2020-09-28 20:11 Highball Status assigned => closed
2020-09-28 20:11 Highball Resolution open => fixed