phillipstanleymarbell / Noisy-lang-compiler

Noisy language compiler
MIT License
17 stars 1 forks source link

Unit factors for constants are propagated wrongly through low precedence operators #425

Open KomaGR opened 5 years ago

KomaGR commented 5 years ago

Describe the bug Unit factor of constant definitions are not propagated correctly through low precedence operators (that is - and +). This makes statements using said constants result in Mismatched physics in expression semantic error.

To Reproduce Steps to reproduce the behavior:

  1. Create a constant with some unit factor (e.g. foo: constant 1 m)
  2. Create invariant with two signals with the same unit factor as parameters (e.g. bar: distance, baz: distance) and operate on them using lowPrecedenceOperators. (e.g. bar == foo + baz)
  3. Try to compile.

Expected behavior Compiler passes. Dimensional matrix is output.

Host OS (please complete the following information):

You local changes (please complete the following information):



**Additional context**
Bug file was created under `applications/newton/bugs`.
phillipstanleymarbell commented 5 years ago

After https://github.com/phillipstanleymarbell/Noisy-lang-compiler/commit/85110cba91c09a64e7d48adb6a2c9ffb51d5c6cb

./newton-darwin-EN ./test-bug-425.nt -P

Informational Report:
---------------------
Invariant "dist" has 2 unique kernels, each with 1 column(s)...

    Kernel 0 is a valid kernel:

          -1
           1

        The ordering of parameters is:  P1 P0 

            Pi group 0, Pi 0 is:    P0^( 1)  P1^(-1)  

    Kernel 1 is a valid kernel:

          -1
           1

        The ordering of parameters is:  P0 P1 

            Pi group 1, Pi 0 is:    P0^(-1)  P1^( 1)  
KomaGR commented 5 years ago

Bug seems fixed for case described in file bug-425.nt. However, it seems that the bug still persists in the case where the unit is derived by some expression as shown in file bug-425-2.nt. When using the symbol for acceleration (line 29) it succeeds.

phillipstanleymarbell commented 5 years ago

See also #402.