Skip to content

Unhandled System.ArgumentOutOfRangeException from P compiler when accessing a variable of a machine reference #920

@tylergu

Description

@tylergu

The P compiler throws an unhandled exception instead of reporting syntax error when the program is accessing a variable of a machine reference.
While this is not allowed in P's language specification, the compiler should report a syntax error detailing the problematic location of the syntax error, instead of raising an unhandled error without helpful information to debug.

How to reproduce

With the ClientServer example from this repo at Tutorial/1_ClientServer/PSrc/Client.p,
with the following change:

diff --git a/Tutorial/1_ClientServer/PSrc/Client.p b/Tutorial/1_ClientServer/PSrc/Client.p
index 81b88b359..fc6761b3e 100644
--- a/Tutorial/1_ClientServer/PSrc/Client.p
+++ b/Tutorial/1_ClientServer/PSrc/Client.p
@@ -29,6 +29,7 @@ machine Client
   var nextReqId : int;
   var numOfWithdrawOps: int;
   var currentBalance: int;
+  var database : Database;
 
   start state Init {
 
@@ -36,6 +37,7 @@ machine Client
     {
       server = input.serv;
       currentBalance =  input.balance;
+      database = input.serv.database;
       accountId = input.accountId;
       // hacky: we would like request id's to be unique across all requests from clients
       nextReqId = accountId*100 + 1; // each client has a unique account id

Then run:

p compile

Full stack trace:

.. Searching for a P project file *.pproj locally in the current folder
.. Found P project file: /Users/tylergu/repos/P/Tutorial/1_ClientServer/ClientServer.pproj
----------------------------------------
==== Loading project file: /Users/tylergu/repos/P/Tutorial/1_ClientServer/ClientServer.pproj
....... includes p file: /Users/tylergu/repos/P/Tutorial/1_ClientServer/PSrc/Server.p
....... includes p file: /Users/tylergu/repos/P/Tutorial/1_ClientServer/PSrc/Client.p
....... includes p file: /Users/tylergu/repos/P/Tutorial/1_ClientServer/PSrc/AbstractBankServer.p
....... includes p file: /Users/tylergu/repos/P/Tutorial/1_ClientServer/PSrc/ClientServerModules.p
....... includes p file: /Users/tylergu/repos/P/Tutorial/1_ClientServer/PSpec/BankBalanceCorrect.p
....... includes p file: /Users/tylergu/repos/P/Tutorial/1_ClientServer/PTst/TestDriver.p
....... includes p file: /Users/tylergu/repos/P/Tutorial/1_ClientServer/PTst/Testscript.p
----------------------------------------
Parsing ...
Type checking ...
Error: [Internal Error]:
 Specified argument was out of the range of valid values. (Parameter 'expr')
<Please report to the P team or create an issue on GitHub, Thanks!>
Error: [PTool] unhandled exception: System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. (Parameter 'expr')
 Stack Trace:    at Plang.Compiler.Backend.IRTransformer.SimplifyExpression(IPExpr expr) in /home/runner/work/P/P/Src/PCompiler/CompilerCore/Backend/IRTransformer.cs:line 327
   at Plang.Compiler.Backend.IRTransformer.SimplifyRvalue(IPExpr expr) in /home/runner/work/P/P/Src/PCompiler/CompilerCore/Backend/IRTransformer.cs:line 113
   at Plang.Compiler.Backend.IRTransformer.SimplifyStatement(IPStmt statement) in /home/runner/work/P/P/Src/PCompiler/CompilerCore/Backend/IRTransformer.cs:line 384
   at Plang.Compiler.Backend.IRTransformer.SimplifyStatement(IPStmt statement) in /home/runner/work/P/P/Src/PCompiler/CompilerCore/Backend/IRTransformer.cs:line 404
   at Plang.Compiler.Backend.IRTransformer.SimplifyMethod(Function function) in /home/runner/work/P/P/Src/PCompiler/CompilerCore/Backend/IRTransformer.cs:line 33
   at Plang.Compiler.Compiler.Compile(ICompilerConfiguration job) in /home/runner/work/P/P/Src/PCompiler/CompilerCore/Compiler.cs:line 63
   at Plang.CommandLine.RunCompiler(String[] args) in /home/runner/work/P/P/Src/PCompiler/PCommandLine/CommandLine.cs:line 144
   at Plang.CommandLine.Main(String[] args) in /home/runner/work/P/P/Src/PCompiler/PCommandLine/CommandLine.cs:line 40

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions