Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static parameters example in the manual is not working as expected. Compilation should fail but it is not. #21404

Open
raicho81 opened this issue Feb 20, 2023 · 3 comments
Labels
Generics Invalid Code Acceptance Everything related to compiler not complaining about invalid code

Comments

@raicho81
Copy link

raicho81 commented Feb 20, 2023

Description

I have taken this example for static parameters from the manual but it is not working as expected.
It seems the type class (Number) constraints on the value type of the matrices in the example are not working:

type
  Number = int32 or float32
  Matrix[M,N: static int; T: Number] = array[0..(M*N - 1), T]
    # Note how `Number` is just a type constraint here, while
    # `static int` requires us to supply an int value
  AffineTransform2D[T] = Matrix[3, 3, T]
  AffineTransform3D[T] = Matrix[4, 4, T]

var m1: AffineTransform3D[float]  # OK
var m2: AffineTransform2D[string] # This should generate error - `string` is not a `Number` and compilation should fail

Nim Version

Nim Compiler Version 1.9.1 [Linux: amd64]
Compiled at 2023-02-20
Copyright (c) 2006-2023 by Andreas Rumpf

git hash: e896977
active boot switches: -d:release

Current Output

Hint: used config file '/home/raych/prg/Nim/config/nim.cfg' [Conf]
Hint: used config file '/home/raych/prg/Nim/config/config.nims' [Conf]
......................................................................
/home/raych/prg/nim_examples_from_manual/static_types_ex.nim(10, 5) Hint: 'm2' is declared but not used [XDeclaredButNotUsed]
/home/raych/prg/nim_examples_from_manual/static_types_ex.nim(9, 5) Hint: 'm1' is declared but not used [XDeclaredButNotUsed]
CC: static_types_ex.nim
Hint:  [Link]
Hint: mm: orc; threads: on; opt: none (DEBUG BUILD, `-d:release` generates faster code)
27551 lines; 0.124s; 30.32MiB peakmem; proj: /home/raych/prg/nim_examples_from_manual/static_types_ex.nim; out: /home/raych/prg/nim_examples_from_manual/static_types_ex [SuccessX]
Hint: /home/raych/prg/nim_examples_from_manual/static_types_ex [Exec]

Expected Output

Compiler error should be produced and the compilation should fail.

Possible Solution

No response

Additional Information

No response

@metagn
Copy link
Collaborator

metagn commented Feb 22, 2023

see #21181

@juancarlospaco
Copy link
Collaborator

!nim c

type
  Number = int32 or float32
  Matrix[M,N: static int; T: Number] = array[0..(M*N - 1), T]
  AffineTransform2D[T] = Matrix[3, 3, T]
  AffineTransform3D[T] = Matrix[4, 4, T]
var m1: AffineTransform3D[float]  
var m2: AffineTransform2D[string]

@github-actions
Copy link
Contributor

github-actions bot commented Jul 7, 2023

@juancarlospaco (contributor)

devel :+1: OK

Output


Stats

  • Created 2023-07-07T11:10:28Z
  • Started 2023-07-07T11:11:02
  • Finished 2023-07-07T11:11:02
  • Duration 1 minute
  • Commands nim c --run -d:strip -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --threads:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
stable :+1: OK

Output


Stats

  • Created 2023-07-07T11:10:28Z
  • Started 2023-07-07T11:11:03
  • Finished 2023-07-07T11:11:03
  • Duration 1 minute
  • Commands nim c --run -d:strip -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --threads:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
1.6.0 :+1: OK

Output


Stats

  • Created 2023-07-07T11:10:28Z
  • Started 2023-07-07T11:11:06
  • Finished 2023-07-07T11:11:07
  • Duration 1 minute
  • Commands nim c --run -d:strip -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --threads:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
1.4.0 :+1: OK

Output


Stats

  • Created 2023-07-07T11:10:28Z
  • Started 2023-07-07T11:11:10
  • Finished 2023-07-07T11:11:11
  • Duration 1 minute
  • Commands nim c --run -d:strip -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --threads:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
1.2.0 :+1: OK

Output


Stats

  • Created 2023-07-07T11:10:28Z
  • Started 2023-07-07T11:11:25
  • Finished 2023-07-07T11:11:26
  • Duration now
  • Commands nim c --run -d:strip -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --threads:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
1.0.0 :+1: OK

Output


Stats

  • Created 2023-07-07T11:10:28Z
  • Started 2023-07-07T11:11:38
  • Finished 2023-07-07T11:11:39
  • Duration now
  • Commands nim c --run -d:strip -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --threads:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
🤖 Bug found in 41 minutes bisecting 6 commits at 0 commits per second.

@metagn metagn added Generics Invalid Code Acceptance Everything related to compiler not complaining about invalid code labels Aug 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Generics Invalid Code Acceptance Everything related to compiler not complaining about invalid code
Projects
None yet
Development

No branches or pull requests

3 participants