Skip to content
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

feat: look for trys on falliable functions with empty error unions #153

Open
DonIsaac opened this issue Dec 12, 2024 · 0 comments
Open

feat: look for trys on falliable functions with empty error unions #153

DonIsaac opened this issue Dec 12, 2024 · 0 comments
Labels
A-linter Area - linter and lint rules C-rule Category - Lint rule suggestion good first issue Good for newcomers

Comments

@DonIsaac
Copy link
Owner

This pathological code compiles when it shouldn't.

const std = @import("std");

fn foo() !u32 {
 return 1;
}

fn bar() void {
  const i = try foo();
  std.debug.print("foo() returns {d}\n", .{i});
}

We should add a rule checking falliable functions and make sure they do one of the following:

  1. Return an error
  2. Use try
  3. Return a call to a function that returns an error union

Item 3 is not fully doable without a type checker, but we can allow cases that return any function call.

@DonIsaac DonIsaac added A-linter Area - linter and lint rules C-rule Category - Lint rule suggestion labels Dec 12, 2024
@DonIsaac DonIsaac added the good first issue Good for newcomers label Dec 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-linter Area - linter and lint rules C-rule Category - Lint rule suggestion good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant