Skip to content

cedar-policy-2.4.2: type error when applying the ? operator #205

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

Open
lcnr opened this issue May 8, 2025 · 3 comments
Open

cedar-policy-2.4.2: type error when applying the ? operator #205

lcnr opened this issue May 8, 2025 · 3 comments
Labels
from-crater A regression found via a crater run, not part of our test suite

Comments

@lcnr
Copy link
Contributor

lcnr commented May 8, 2025

[INFO] [stdout] error[E0277]: `?` couldn't convert the error to `serde_json::Error`
[INFO] [stdout]     --> /opt/rustwide/cargo-home/registry/src/index.crates.io-1949cf8c6b5b557f/cedar-policy-2.4.2/src/api.rs:1410:76
[INFO] [stdout]      |
[INFO] [stdout] 1410 |             parsed.into_euid(|| JsonDeserializationErrorContext::EntityUid)?,
[INFO] [stdout]      |                    --------------------------------------------------------^ the trait `From<cedar_policy_core::entities::JsonDeserializationError>` is not implemented for `serde_json::Error`
[INFO] [stdout]      |                    |
[INFO] [stdout]      |                    this can't be annotated with `?` because it has type `Result<_, cedar_policy_core::entities::JsonDeserializationError>`
[INFO] [stdout]      |
[INFO] [stdout]      = note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait
[INFO] [stdout] 
[INFO] [stdout] 
[INFO] [stdout] error[E0308]: mismatched types
[INFO] [stdout]     --> /opt/rustwide/cargo-home/registry/src/index.crates.io-1949cf8c6b5b557f/cedar-policy-2.4.2/src/api.rs:1409:9
[INFO] [stdout]      |
[INFO] [stdout] 1406 |       pub fn from_json(json: serde_json::Value) -> Result<Self, impl std::error::Error> {
[INFO] [stdout]      |                                                    ------------------------------------ expected `Result<api::EntityUid, impl StdError>` because of return type
[INFO] [stdout] ...
[INFO] [stdout] 1409 | /         Ok::<Self, entities::JsonDeserializationError>(Self(
[INFO] [stdout] 1410 | |             parsed.into_euid(|| JsonDeserializationErrorContext::EntityUid)?,
[INFO] [stdout] 1411 | |         ))
[INFO] [stdout]      | |__________^ types differ
[INFO] [stdout]      |
[INFO] [stdout]      = note: expected enum `Result<_, serde_json::Error>`
[INFO] [stdout]                 found enum `Result<_, cedar_policy_core::entities::JsonDeserializationError>`
@lcnr lcnr added the from-crater A regression found via a crater run, not part of our test suite label May 8, 2025
@lcnr lcnr moved this to unknown in -Znext-solver=globally May 8, 2025
@lcnr
Copy link
Contributor Author

lcnr commented May 9, 2025

minimized

fn foo() -> Result<(), impl Sized> {
    Err(1u16)?;
    Err(1u32)
}
fn main() {}

@lcnr
Copy link
Contributor Author

lcnr commented May 9, 2025

side-effect of our fix for #196.

fn foo() -> impl Sized {
    if false {
        return From::from(1u16);
    }

    1u32
}

we should not use the blanket impl of From here ☠ I think we kind of want:

  • only item-bounds may guide inference, blanket impls must only be used to "get to" item bounds. no idea how one would impl that :3

@lcnr
Copy link
Contributor Author

lcnr commented May 9, 2025

idea for a very limited approach:

  • only search for blanket impls which
    • have a param self type
    • do not mention that param anywhere else in either the impl header or non-self position of where-clauses
    • recur into the where-clauses with a param self

how do we want to handle the following

trait IntoIterator<Unused = ()> {
    type Item;
}

impl<I: Iterator> IntoIterator<()> for I {
    type Item = I::Item;
}

fn assoc<T: IntoIterator>(x: T) -> T::Item {
    loop {}
}

fn should_be_ok() -> impl IntoIterator<Item = u32> {
    assoc(should_be_ok()).count_zeros();
    vec![].into_iter()
}

fn should_be_ambig<T, U>(x: U) -> impl IntoIterator<T, Item = u32>
where
    U: IntoIterator<T, Item = u32> + Copy + IntoIterator<Item = u32> + Copy,
{
    // `<opaque<?t, U> as IntoIterator<()>>::Assoc
    assoc(should_be_ambig(x)).count_zeros();
    x
}

we could check whether equating the non-self impl trait refs holds without returning any inference constraints.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
from-crater A regression found via a crater run, not part of our test suite
Projects
Status: unknown
Development

No branches or pull requests

1 participant