chaos-lang / chaos

The Chaos Programming Language
https://chaos-lang.org
GNU General Public License v3.0
281 stars 17 forks source link

[RFC] Multiline Preemptive Error Report #99

Closed mertyildiran closed 3 years ago

mertyildiran commented 3 years ago

Right now preemptive error checker exists if it encounter an issue. For example if you run chaos tests/shell/preemptive.kaos then it just prints this output:

  Preemptive Error:                                        
    File: "tests/shell/preemptive.kaos", line 47, in a     
      num b = f5()                                         
  Undefined function: f5 in <module>                       

If the number of issues are big, it might be hard to see them one by one. Therefore we need to detect all the issues at once and print a multiline preemptive error report like this:

  Preemptive Errors:                                                                    
    File: "tests/shell/preemptive.kaos", line 2, in f4     
      print b                                                                          
  Undefined variable: b                                                                
  ---
    File: "tests/shell/preemptive.kaos", line 27, in f4     
      n1 > 10 : f2(),                                                                   
  Undefined variable: n1                                                                
  ---
    File: "tests/shell/preemptive.kaos", line 39, in f4     
      z > 10  : f2(n2),                                                                 
  Undefined variable: n2                                                                
  ---
    File: "tests/shell/preemptive.kaos", line 47, in a     
      num b = f5()                                                                     
  Undefined function: f5 in <module>                                                   
  ---
    File: "tests/shell/preemptive.kaos", line 58, in f4     
      z > 10  : f6(),                                                                   
  Undefined function: f6 in <module>                                                    
  ---
    File: "tests/shell/preemptive.kaos", line 69, in f1     
      z == 8  : f1(z),                                                                  
  Incorrect argument count for function: f1                                             
  ---
    File: "tests/shell/preemptive.kaos", line 79, in f1     
      num x = f1(c)                                                                     
  Incorrect argument count for function: f1                                             
  ---
    File: "tests/shell/preemptive.kaos", line 98, in f8     
      f8(a, b)                                                                          
  Illegal variable type for function parameter: b of function: f8                       
  ---
    File: "tests/shell/preemptive.kaos", line 104, in f8     
      f8(3, 5)                                                                           
  Illegal variable type for function parameter: b of function: f8                        
  ---
    File: "tests/shell/preemptive.kaos", line 112, in f8     
      f8(a, b)                                                                           
  Illegal variable type for function parameter: a of function: f8                        
  ---
    File: "tests/shell/preemptive.kaos", line 118, in f8     
      f8([1, 2, 3], 'hello')                                                             
  Illegal variable type for function parameter: a of function: f8                        
  ---
    File: "tests/shell/preemptive.kaos", line 127, in f8     
      f8(a, b, c)                                                                        
  Incorrect argument count for function: f8                                              
  ---
    File: "tests/shell/preemptive.kaos", line 133, in f8     
      f8(3, 'hello', true)                                                               
  Incorrect argument count for function: f8                                              
  ---
    File: "tests/shell/preemptive.kaos", line 141, in f4     
      return a                                                                           
  Illegal variable type: Dictionary for function: f4                                     
  ---
    File: "tests/shell/preemptive.kaos", line 148, in f4     
      return b                                                                           
  Undefined variable: b                                                                  
  ---
    File: "tests/shell/preemptive.kaos", line 158, in f4     
      x == 5  : return a,                                                                
  Illegal variable type: Dictionary for function: f4                                     
  ---
    File: "tests/shell/preemptive.kaos", line 168, in f4     
      x == 5  : return b,                                                                
  Undefined variable: b                                                                  
  ---
    File: "tests/shell/preemptive.kaos", line 176, in f4     
      end                                                                                
  The function 'f4' did not return anything!                                             
  --
    File: "tests/shell/preemptive.kaos", line 183, in f4     
      print b                                                                            
  Undefined variable: b                                                                  
  ---
    File: "tests/shell/preemptive.kaos", line 193, in f4     
      n times do                                                                         
  Undefined variable: n                                                                  
  ---
    File: "tests/shell/preemptive.kaos", line 201, in f4     
      foreach a as el                                                                    
  Undefined variable: a                                                                  
  ---
    File: "tests/shell/preemptive.kaos", line 221, in f4     
      print b                                                                            
  Undefined variable: b                                                                  
  ---
    File: "tests/shell/preemptive.kaos", line 242, in f4     
      print b                                                                            
  Undefined variable: b                                                                  
  ---
    File: "tests/shell/preemptive.kaos", line 264, in f4     
      print f11(el, 1)                                                                   
  Undefined function: f11 in <module>                                                    
  --
    File: "tests/shell/preemptive.kaos", line 271, in f4     
      foreach a as el                                                                    
  'a' is not a list!                                                                     
  ---                                                               
    File: "tests/shell/preemptive.kaos", line 280, in f4     
      foreach a as key : val                                                             
  'a' is not a dictionary!                                                               
  ---
    File: "tests/shell/preemptive.kaos", line 290, in f9     
      num r = f9(x, y)                                                                   
  Call to a function with `break` from outside a loop: f9                                
  ---
    File: "tests/shell/preemptive.kaos", line 299, in f9     
      print f9(el, 1)                                                                    
  Call to a function with `break` from a multiline loop: f9                              
mertyildiran commented 3 years ago

Implemented with https://github.com/chaos-lang/chaos/commit/1921ee9e90e6944223bfd4a198b812f8d75078dd