Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: crystal-lang/crystal
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: b2def93dc9d0
Choose a base ref
...
head repository: crystal-lang/crystal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: c87fc6dd81ba
Choose a head ref
  • 3 commits
  • 4 files changed
  • 1 contributor

Commits on May 21, 2017

  1. Fixed wrong require in spec

    Ary Borenszweig committed May 21, 2017
    Copy the full SHA
    be703a2 View commit details
  2. Codegen: add missing location to raise

    Ary Borenszweig committed May 21, 2017
    Copy the full SHA
    6141bcd View commit details
  3. Copy the full SHA
    c87fc6d View commit details
Showing with 34 additions and 5 deletions.
  1. +24 −0 spec/compiler/semantic/macro_spec.cr
  2. +1 −1 spec/std/callstack_spec.cr
  3. +2 −1 src/compiler/crystal/codegen/codegen.cr
  4. +7 −3 src/compiler/crystal/types.cr
24 changes: 24 additions & 0 deletions spec/compiler/semantic/macro_spec.cr
Original file line number Diff line number Diff line change
@@ -1060,4 +1060,28 @@ describe "Semantic: macro" do
{global(1), global(1, 2)}
)) { tuple_of [int32, char] }
end

it "finds macro and method at the same scope inside included module" do
assert_type(%(
module Moo
macro global(x)
1
end
def global(x, y)
'a'
end
end
class Foo
include Moo
def main
{global(1), global(1, 2)}
end
end
Foo.new.main
)) { tuple_of [int32, char] }
end
end
2 changes: 1 addition & 1 deletion spec/std/callstack_spec.cr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require "../spec_helper"
require "spec"
require "tempfile"

describe "Backtrace" do
3 changes: 2 additions & 1 deletion src/compiler/crystal/codegen/codegen.cr
Original file line number Diff line number Diff line change
@@ -1248,7 +1248,8 @@ module Crystal

def cant_pass_closure_to_c_exception_call
@cant_pass_closure_to_c_exception_call ||= begin
call = Call.global("raise", StringLiteral.new("passing a closure to C is not allowed"))
location = Location.new(@program.filename, 1, 1)
call = Call.global("raise", StringLiteral.new("passing a closure to C is not allowed")).at(location)
@program.visit_main call
call
end
10 changes: 7 additions & 3 deletions src/compiler/crystal/types.cr
Original file line number Diff line number Diff line change
@@ -373,7 +373,11 @@ module Crystal
end

def has_def?(name)
defs.try(&.has_key?(name)) || parents.try(&.any?(&.has_def?(name)))
has_def_without_parents?(name) || parents.try(&.any?(&.has_def?(name)))
end

def has_def_without_parents?(name)
defs.try(&.has_key?(name))
end

record DefInMacroLookup
@@ -399,7 +403,7 @@ module Crystal
# First check if there are defs at this scope with that name.
# If so, make that a priority in the lookup and don't consider
# macro matches.
if has_def?(name)
if has_def_without_parents?(name)
return DefInMacroLookup.new
end

@@ -423,7 +427,7 @@ module Crystal
return macros
end

if has_def?(name)
if has_def_without_parents?(name)
return DefInMacroLookup.new
end