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

Wrong C code generated on operations on sets #16269

Closed
lscrd opened this issue Dec 6, 2020 · 9 comments
Closed

Wrong C code generated on operations on sets #16269

lscrd opened this issue Dec 6, 2020 · 9 comments

Comments

@lscrd
Copy link

lscrd commented Dec 6, 2020

The C compiler issues an error when compiling a program which contains operations (for instance, +) on sets with different types.

Example

var s1: set[char]
var s2: set['a'..'z']
s1 = s1 + s2

Current Output

C compiler error encountered on line:

s1__etK2abcqxo7K0et3U5RHIg[T1_] = s1__etK2abcqxo7K0et3U5RHIg[T1_] | s2__vKC9bTRzNfAnygP9bmyHDlDg[T1_];

Expected Output

Program compiles without error.

Possible Solution

Do not use operations between a set of a type and a set of a subtype.

Additional Information

$ nim -v
Nim Compiler Version 1.4.2 [Linux: amd64]
Compiled at 2020-11-30
Copyright (c) 2006-2020 by Andreas Rumpf

git hash: 3fb5157ab1b666a5a5c34efde0f357a82d433d04
active boot switches: -d:release

Doesn’t work with development version either.

@metagn
Copy link
Collaborator

metagn commented Dec 6, 2020

Same as #15435?

@lscrd
Copy link
Author

lscrd commented Dec 6, 2020

This issues are likely related but the error detected by the C compiler is not the same. As my system is localized, the message is in French.

For #15435 the first error is:

erreur: le transtypage spécifie un type de tableau
180 |   T4_ = ((TM__6x2C9bN0rvuU6HnSvx4zF9aQ_2[T3_] & ~ ((tySet_tyUInt8__k3HXouOuhqAKq0dx450lXQ) (x__9bvrpNC9cbtMYpvjyjwnjxZA))[T3_]) == 0);

With my example, this is:

erreur: la valeur de l'indice n'est ni un tableau ni un pointeur ni un vecteur
131 |   s1__q5c6FUUkqcJ2oGYGGyNlCQ[T1_] = s1__q5c6FUUkqcJ2oGYGGyNlCQ[T1_] | s2__LDX8PQmqIiTZpeAWmW9cQoA[T1_];

@metagn
Copy link
Collaborator

metagn commented Dec 6, 2020

For #15435 the first error is

The first error is for the < operation. I added the + operation at the end after you made this issue, and the error for the + codegen in that issue is similar. In the title, you wrote that it happens on "operations on sets" so you would know that it'll error regardless of the operation

@lscrd
Copy link
Author

lscrd commented Dec 6, 2020

I searched similar issues but was unable to find the #15435 issue :-(. But I agree: this is the same error and #16270 is probably also the same with a different behavior.

@kaushalmodi
Copy link
Contributor

@lscrd

Expected Output
Program compiles without error.

I am getting this error on the latest devel, which makes sense.

t16269.nim(6, 9) Error: type mismatch: got <set[char], set[range 97..122(char)]>
but expected one of:
func `+`[T](x, y: set[T]): set[T]
  first type mismatch at position: 2
  required type for y: set[T]
  but expression 's2' is of type: set[range 97..122(char)]

@lscrd
Copy link
Author

lscrd commented Nov 1, 2021

@kaushalmodi

We get this error with version 1.6.0 too.

When I wrote that I expected the program to compile without error, I meant that I expected no error when compiling the generated C program. One way to solve this was to introduce some restrictions on types for certain operations, which I understand.

So, for me this error makes sense too.

@kaushalmodi
Copy link
Contributor

Thanks for confirming. It then looks like this issue is a duplicate of #15435; can you review the test added for that issue in this PR: https://github.com/nim-lang/Nim/pull/19079/files ?

This issue can then be closed if it's a duplicate.

@lscrd
Copy link
Author

lscrd commented Nov 1, 2021

Yes. It’s a duplicate of #15435. For the test added in the PR, I think that last line is useless as this is line 5 which causes a compilation error. Of course, if we comment lines 5 and 6, this last line will also cause a compilation error.

I close the present issue.

@lscrd lscrd closed this as completed Nov 1, 2021
@kaushalmodi
Copy link
Contributor

kaushalmodi commented Nov 1, 2021

For the test added in the PR, I think that last line is useless as this is line 5 which causes a compilation error.

You're right :) I have removed that unnecessary line from that test as it will never be reached.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants