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

Memory error when checking if a variable is a string in concept #7092

Closed
okamsn opened this Issue Jan 16, 2018 · 4 comments

Comments

Projects
None yet
6 participants
@okamsn
Copy link

okamsn commented Jan 16, 2018

Hello, the following code compiles and then fails to run:

type stringTest = concept x
  x is string

let a: stringTest = "111"

It gives the error

Traceback (most recent call last)
string_err.nim(5) string_err
SIGSEGV: Illegal storage access. (Attempt to read from nil?)

When doing

type stringTest = concept x
  x is string

let a: stringTest = "111"
let b: stringTest = "01"

I get the message "out of memory". This is on Ubuntu 17.10 with Nim 17.3.

I feel like this should work, but I am still learning the language, and so am not sure why it wouldn't.

@Yardanico

This comment has been minimized.

Copy link
Collaborator

Yardanico commented Jan 16, 2018

@okamsn stringTest is a concept, not a concrete type. You can't create an object of a concept type.
https://nim-lang.org/docs/manual.html#generics-concepts

@zah zah self-assigned this Jan 16, 2018

@okamsn

This comment has been minimized.

Copy link

okamsn commented Jan 16, 2018

Alright, so if I was trying to make a type that has certain requirements, should I be using a concept?

I know that the following code does run and compile in the same setup.

type intTest = concept x
  x is int

let a: intTest = 1
echo a

Is there some automatic conversion going on here, then?

@zah

This comment has been minimized.

Copy link
Member

zah commented Jan 17, 2018

In this context, the concept is just used to verity that the value or the right-hand side of the assignment conforms to the concept requirements. The variables will end up with the concrete type of that value (here, this is string or int). There shouldn't be a crash, so this is a genuine bug that must be investigated.

@Araq Araq added this to the v1 milestone Jun 8, 2018

@DavidMeagher1

This comment has been minimized.

Copy link

DavidMeagher1 commented Sep 21, 2018

this might be old, but i did find it works fine with cstrings

type cstringTest = concept x
  x is cstring

let a = cstringTest("hello".cstring)
echo a

@Araq Araq closed this in bf85955 Oct 2, 2018

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