Skip to content

Add type restrictions to spec#16068

Closed
Vici37 wants to merge 1 commit intocrystal-lang:masterfrom
Vici37:add-type-restrictions-to-spec
Closed

Add type restrictions to spec#16068
Vici37 wants to merge 1 commit intocrystal-lang:masterfrom
Vici37:add-type-restrictions-to-spec

Conversation

@Vici37
Copy link
Contributor

@Vici37 Vici37 commented Aug 6, 2025

This is the output of compiling cr-source-typer and running it with the below incantation:

CRYSTAL_PATH="./src" ./typer spec/std_spec.cr \
  --error-trace --exclude src/crystal/ \
  --stats --progress \
  --union-size-threshold 2 \
  --ignore-private-defs \
  src/spec

This is related to #15682 .

This touched more than I expected, but everything looks correct to me. Comments always welcome :)

…Vici37/cr-source-typer) and running it with the below incantation:

```
CRYSTAL_PATH="./src" ./typer spec/std_spec.cr \
  --error-trace --exclude src/crystal/ \
  --stats --progress \
  --union-size-threshold 2 \
  --ignore-private-defs \
  src/spec
```

This is related to crystal-lang#15682 .
Comment on lines +96 to 97
def negative_failure_message(actual_value : Bool?) : String
"Expected: #{actual_value.pretty_inspect} not to be truthy"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the message is correct and this accept truthy values, then Bool? is too restrictive.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yup, good catch

end

def failure_message(actual_value)
def failure_message(actual_value : Bool?) : String
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Copy link
Member

@straight-shoota straight-shoota left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it makes much sense to add type restrictions to undocumented, internal APIs. They mostly create noise and require review effort without much benefit.
Just glancing over it, I notice a few odd things but I don't want to put in the effort to review and fix them. It's just not worth it.

This obviously doesn't mean we should never use type restrictions on internal APIs, but it be for a reason. Not sprinkle some autogenerated type annotations everywhere.

@Vici37
Copy link
Contributor Author

Vici37 commented Aug 7, 2025

Yup, fair enough. I'm fine closing this PR based on that @straight-shoota - the crystal core team would be the main consumers of these internal API type restrictions, and if you don't want them, then they serve no purpose :)

@Vici37 Vici37 closed this Aug 7, 2025
@straight-shoota
Copy link
Member

The methods in src/spec/methods.cr are public, maybe we could merge at least those type restrictions?

@Vici37
Copy link
Contributor Author

Vici37 commented Aug 7, 2025

I'll create a new PR for just that file then. Current new feature for the typifier is to optionally ignore :nodoc: classes / methods for type restriction application.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants