luckyframework / luckyframework/lucky

Declaring "needs" for a component with a Proc fails to compile

Open
#1,269 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

usability
Dominant language
Crystal
Stars
2.7k
Forks
172
PR merge metrics
No merged PRs in 30d

Description

Passing procs as parameters can be really helpful for named slots in Lucky components, as shown here:
https://www.youtube.com/watch?v=KoiKOD63tRQ

This episode originated from a snippet provided by @paulcsmith here:
https://gist.github.com/paulcsmith/01c1ced3e681de99d0ec343fdf57e2b7#gistcomment-3419386

Specifically, he wanted to be able to write something like:

```crystal
class MyCustomComponent < BaseComponent
needs user : User
needs some_content : ->
needs some_user_content : User->

def render
div do
some_content.call
some_user_content.call(user)
end
end
end
```

However, when using any more than one `needs` when any of them was a Proc, I kept getting a compile-time error of `Error: undefined macro method 'ProcNotation#types`. Switching to using `Proc` for the type worked, but Paul requested that an issue be opened to look into supporting the `->` syntax.

```crystal
class MyCustomComponent < BaseComponent
needs user : User
needs some_content : Proc(Void)
needs some_user_content : Proc(User)

def render
div do
some_content.call
some_user_content.call(user)
end
end
end
```

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by compiling the minimal Crystal component example from the issue, first with arrow Proc syntax and then with Proc types. Trace the needs macro and the ProcNotation#types error to identify why multiple Proc needs fail; done means the arrow syntax compiles for both examples and the component can call each proc.

Written by the indexing model from the issue text.

Assessment

Tech stack
crystal
Domain
web-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.