shama has quit [Remote host closed the connection]
<asterite>
Did you instantiate any plugin before that line?
<jhass>
sure
<jhass>
it's like the 9th plugin I write
<jhass>
and the second most simple one
<jhass>
not sure if I actually had a map before though, let me check
<asterite>
As a workaround, when the compiler can't infer the type of a block you can tell it with `as`
<asterite>
So `issues.map {|issue| "https://github.com/#{@projects[msg.channel.name]}/issues/#{issue[1]}" as String }` should work
<asterite>
I think
<jhass>
mmh, yeah, there's another one with a map that's working
<jhass>
yup, looks like it
<jhass>
"foo" as String seems weird though :P
<jhass>
so block type == block return type?
<jhass>
I think making that clear would help a bit already :)
<asterite>
Yes
<asterite>
Well, it's an interpolation and some part of it is untyped, so the whole expression gets untyped
<asterite>
I promise I'll fix this... somehow. It happened to me many times and I used the "as" workaround, but once it happens to somebody else it's time to fix it :)
<asterite>
Did the "as" thing work?
<jhass>
yes
<asterite>
On the other hand, if we explain that when the compiler tells you "can't infer block return type" you need to help it with an "as" cast, it's not that bad, really
<asterite>
(but I'll fix it)
<asterite>
Compared to other languages, the amount of explicit types you need to write is very low, so once in a while helping the compiler will have to happen, I guess
<jhass>
yes, I think that's still a good thing to do as an interim improvement though
<asterite>
What do you think?
<jhass>
so, improve the message and then when you (or somebody else) happens to find a solution, the better
<jhass>
I'd say
<asterite>
Yes, I was going to do that
<asterite>
I can't come up with a nice message, though
<asterite>
"can't infer block type, ...?"
<jhass>
"try casting the return value with `as`" ?
<jhass>
looks like something segfaults when that code is called now :/
<jhass>
oh, I made a stack overflow
<jhass>
ah, so unterminated recursive call, called from within that expression
<jhass>
which is probably why ther inference failed in the first place
<zamith>
the idea is so that it works even if you need any of those chars in the strings
<zamith>
but I've never used anything other than those
<asterite>
Yeah, I think it’s hard to find a case where you need (, { and [ inside a string
<asterite>
zamith: if you’d like to hack the compiler, adding support for %w[ and others can be a small task. But you’ll need to store the delimiter so then you can know when it ends (it’s already implemented for string literals). I’m just suggesting this because you asked about that other lexer-related issue :)
<zamith>
sure, I can give it a go
<zamith>
Do you mean use a Token::DelimiterState?
<zamith>
I think that's the name
<asterite>
Yes, that one. It’s currently use when lexing a string, but you can reuse it in this case (the cases don’t overlap)
<asterite>
There’s also lexer_string_array_spec.cr to understand how it’s used by the parser
<zamith>
it's also used in regexes, right?
<zamith>
that's where I saw it, I believe
<zamith>
I'l give it a look, thanks
<asterite>
Yes
<asterite>
Only if you want to. I can do it too, but the comment on the issue gave me the impression that you wanted to touch the compiler (but I might be wrong!)
<zamith>
Sure
sferik has joined #crystal-lang
<zamith>
I'm not sure how much I'll be able to accomplish, but it won't hurt to give it a try
<zamith>
:)
<asterite>
:)
<asterite>
zamith: where will you give the talk, another ruby meetup?
<zamith>
yeah
<zamith>
it's like 10/12 people at a time
<zamith>
but at least we'll be talking about it
<zamith>
they invited me, because they were interested in the language
<zamith>
:)
<asterite>
That’s really nice to hear! :)
CeBot has quit [Quit: Crystal]
CeBot has joined #crystal-lang
<jhass>
>> `rm -rf /`
<CeBot>
jhass: Sorry, I can't let you do that.
<jhass>
:(
<jhass>
CeBot: why not?
<asterite>
:-D
<asterite>
How do you know when to say that?
<jhass>
when that bad system call message appears in the output ;)
<asterite>
Oh, you are running of the compiler specs?
<asterite>
You need to install llvm 3.5
<zamith>
oh ok
<asterite>
I definitely need to add a page in the docs explaining how to contribute :)
<jhass>
CONTRIBUTING.md in the repo is a convention, I think github even hints it somewhere while forking or doing a PR ;)
<zamith>
Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn)
<zamith>
this is what I have
<asterite>
jhass: good, I’ll do that
<asterite>
Do you have llvm-config in the PATH?
<zamith>
nop
<zamith>
where is that?
<asterite>
Also, when running compiler specs be sure to use bin/crystal instead of crystal, because “src” is not in the CRYSTAL_PATH so it will find the “src” of your installed crystal
<asterite>
It comes with llvm binaries
<asterite>
Who gave you the string “Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn)” ?
<zamith>
clang --version
<asterite>
Oh, maybe you have clang but not llvm
<zamith>
I can try brew --prefix llvm
<asterite>
Sure
<zamith>
and add that to the path
<asterite>
Oh maybe llvm is not linked by default, I did `brew link llvm --force`
sferik has joined #crystal-lang
<zamith>
I don't think so
<zamith>
that works
<zamith>
thanks
<asterite>
Cool!
<zamith>
the linking I mean
sferik__ has quit [Ping timeout: 264 seconds]
<zamith>
asterite: so, I have to store the opening char somewhere. Is an instance variable good enough?
<zamith>
*a
<asterite>
You can store it in Token’s @delimiter_state
<zamith>
ok
<asterite>
You have “kind, nest, :end, open_count” as fields, you can do `Token::DelimiterState.new(:array, ‘(‘, ‘)’, 0)` for example
<asterite>
Oh, about #334, we could add the expect syntax but then there will be two ways to do the same thing. For now there’s no real pressure to change this, I think
asterite_ has joined #crystal-lang
asterite has quit [Ping timeout: 255 seconds]
asterite_ is now known as asterite
_whitelogger__ has joined #crystal-lang
<zamith>
I personally prefer the expect syntax, because it is very is to see what is the object and what is the expectation
<zamith>
but it's ok either way
_whitelogger_ has quit [*.net *.split]
<asterite>
Yes, I just did a couple of changes to see how it looks, and it is indeed a bit more readable
drizz has quit [Quit: d]
<asterite>
but it takes a bit longer to write (pressing shift twice for the parenthesis), plus you have to remember to start with “expect(“, so I’m not sure which one I like most
<zamith>
asterite: I'm trying to move the parsing of string array to the regular delimiters
<zamith>
so, DELIMITER_START and DELIMITER_END, and use the kind to tell them apart
<asterite>
Good :)
<zamith>
it all works well up to parse_delimiter, where I get the pieces correctly, but I want to create an ArrayLiteral, and it breaks
<zamith>
:s
<asterite>
how it breaks?
<zamith>
case delimiter_state.kind
<zamith>
when :command
<zamith>
result = Call.new(nil, "`", result)
<zamith>
when :regex
<zamith>
result = RegexLiteral.new(result, modifiers)
<zamith>
and in /Users/zamith/Projects/personal/crystal/crystal/src/compiler/crystal/syntax/to_s.cr:91: undefined method 'accept' for String
<zamith>
exp.accept self
<zamith>
this
<asterite>
Oh, the method to parse that is parse_string_or_symbol_array
drizz has joined #crystal-lang
<zamith>
I know
<zamith>
I'm trying to get rid of that
<asterite>
Oh, so you want to unify both methods?
<zamith>
because it has nothing special really, apart from the fact that the pieces are put together into an array
<zamith>
yes
<asterite>
Ah, it breaks because pieces is `pieces = [] of ASTNode | String`, so you are passing a String to an ArrayLiteral.new
<zamith>
pieces is Array((Crystal::ASTNode+ | String))
<zamith>
at least that's what .class says
<asterite>
Yes, and if you do `ArrayLiteral.new(pieces)` it will fail because it expects an Array(ASTNode) (not of String)
<zamith>
I tried pieces of ASTNode
<zamith>
but it doesn't work
<zamith>
:S
<zamith>
is there a way to do this?
<asterite>
with an `as` or how?
<zamith>
sorry?
<asterite>
“I tried pieces of ASTNode” -> what do you mean?
<zamith>
pieces as Array(ASTNode)?
<zamith>
I tried with of
<zamith>
what's the difference?
<asterite>
`of` is just for the array/hash literal literal syntax
<zamith>
as is type casting?
<asterite>
but you can’t use `as` for what you want
<zamith>
oh ok
<asterite>
yes, but the cast should fail if any of the elements in the array is indeed a String
<zamith>
yeah
<zamith>
it does
<zamith>
:)
<zamith>
it has to be a StringLiteral?
<asterite>
I mean, if we decide to allow this case, at runtime this must be checked
<asterite>
but it’s expensive
<zamith>
I can map over it and transform into string literals, right?
<zamith>
like it does for interpolations
<asterite>
Yes, that might work
<asterite>
The error you got when you did `ArrayLiteral.new(pieces)` was probably long and hard to understand, right?
<zamith>
yup
<zamith>
but I guess it's internal
<zamith>
so, not a big issue
<asterite>
No, it’s not internal :(
<asterite>
but with the global type inference it gets harder to correctly report errors
<asterite>
What I usually do is go line by line (in the error trace) and see where is a method call with a type I know shouldn’t be there
<asterite>
One of the lines is: instantiating 'Crystal::ArrayLiteral:Class#new((Array((Crystal::ASTNode+ | String)) | Array(Crystal::ASTNode+)))'
<asterite>
so there it says that ArrayLiteral.new is invoked with a union of things that don’t make sense (for the programmer)
<zamith>
hum...
<asterite>
But if anyone thinks of a better way to report these errors, you are very welcome :)
<zamith>
so this is the error for any bad invocation?
<asterite>
Yes. Well, it depends on where the error happened
r20 has quit [Quit: Leaving]
<asterite>
The last line in the error is “undefined method 'accept' for String” in “exp.accept self”, underlining “exp”
<asterite>
So the compiler deduced exp can potentially be a String
<asterite>
and that exp came from the ArrayLiteral @exps variable
<asterite>
Kind of hard to explain… in Ruby you would get the same error, you would get “undefined method accept for String” and then you’ll have to figure how a String came into that variable (or a nil, which is the most common case)
<asterite>
only here you get a backtrace of the origin of that type… I don’t know if there’s a better way to do it
<zamith>
it looks like a hard problem
<zamith>
but a lot of output sometimes is bad, it looks scary
<zamith>
:P
<zamith>
the delimiter being tokenized as START STRING END
<zamith>
even though the STRING has spaces
<zamith>
the spaces should be a separator
<zamith>
is that because of how regular delimited things work?
<asterite>
The spaces are only separators when you do %w(foo bar)
<asterite>
but in “foo bar” they are just part of the STRING
<zamith>
yeah...
<asterite>
I’m not sure it’ll be easy to unify the two methods. One invokes next_string_token, the other one invokes next_string_array_token
<asterite>
Or: I would try to make it work first, and then refactor (if possible)
<zamith>
ok
<asterite>
Explaining you the error messages I think I can improve them by pointing you to the main line that caused the error to propagate. I’ll try :)
<zamith>
i like how the stack trace is inverted
<zamith>
and i only have to look to the line right above the prompt
<asterite>
There are actually two traces: one for where the type leading to the error originated, and one for the instantiation backtrace. But sometimes the line right above the prompt gives you a hint but you have to look at the whole thing to understand it
<zamith>
in /Users/zamith/Projects/personal/crystal/crystal/src/compiler/crystal/codegen/target_machine.cr:11: undefined method 'from_triple' for LLVM::Target:Class
<zamith>
asterite: is this an issue with the llvm?
<asterite>
We added that a few days ago, you might need to git pull
<asterite>
Oh
<asterite>
And remember to always use bin/crystal when developing the compiler, otherwise you will always use the old source code
sferik has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<zamith>
I think I broke bin/crystal
<zamith>
:P
<zamith>
was trying to compile it with the 0.5.8 release
<zamith>
i have an idea
<zamith>
I just checked out to master and built it here
<zamith>
;)
<jhass>
>> module A; end; class B; include A; end; class D(T); end; a = [] of D(A); a << D(B).new
<CeBot>
jhass: [#<D(B):0x95C4FF8>]
<jhass>
^ that works fine
<jhass>
no overload matches 'Array({Framework::PluginContainer(Framework::Plugin), Array(String)})#<<' with types {Framework::PluginContainer(Google), Array(String)}
<CeBot>
jhass: in line 3: undefined macro method TupleLiteral#argify'
<asterite>
Ah, sorry, I just began reading it. It’s interesting the way it’s done. I think jhass wanted to do it that way too but we ran into some issues
<jhass>
yeah, the "running code in the context of this random instance" aka with yield is too limited
<asterite>
jhass: that’s a “bug” (you should be able to splat a tuple)