lgwillmore / warden

Kotlin Attribute Based Access Control
MIT License
19 stars 3 forks source link

'boolean' in package name causes error: <identifier> expected #34

Closed aSemy closed 2 years ago

aSemy commented 2 years ago

I get an error when compiling with 'policies' defined as a static variable

This might be related to kapt?

I'm using Kotlin/JVM 1.7.0 and Warden 0.1.0

This code causes the error:

import codes.laurence.warden.policy.boolean.allOf

val policies = listOf(
    // Any User can read any Article
    allOf {
        resource("type") equalTo "Article"
        action("type") equalTo "READ"
    },
)

fun main() {
}

This is the generated code. It thinks that 'boolean' is an identifier.

import java.lang.System;
@kotlin.Metadata(mv = {1, 7, 1}, k = 2, d1 = {"\u0000\u0014\n\u0000\n\u0002\u0010 \n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0010\u0002\n\u0000\u001a\u0006\u0010\u0005\u001a\u00020\u0006\"\u0017\u0010\u0000\u001a\b\u0012\u0004\u0012\u00020\u00020\u0001\u00a2\u0006\b\n\u0000\u001a\u0004\b\u0003\u0010\u0004\u00a8\u0006\u0007"}, d2 = {"policies", "", "Lcodes/laurence/warden/policy/boolean/AllOf;", "getPolicies", "()Ljava/util/List;", "main", "", "application-core"})
public final class MainKt {
    @org.jetbrains.annotations.NotNull()
    private static final java.util.List<codes.laurence.warden.policy.boolean.AllOf> policies = null;

    @org.jetbrains.annotations.NotNull()
    public static final java.util.List<codes.laurence.warden.policy.boolean.AllOf> getPolicies() {
        return null;
    }

    public static final void main() {
    }
}
image
.../service/application-core/build/tmp/kapt3/stubs/main/MainKt.java:7: error: <identifier> expected
    private static final java.util.List<codes.laurence.warden.policy.boolean.AllOf> policies = null;
                                                                     ^

See also

lgwillmore commented 2 years ago

I have not used this with kotlin 1.7 yet. Our production is still on 1.6.

I doubt that the change to 1.7 would cause this sort of conflict though, so I can only assume it is related to something else... possibly the kapt compiler plugin you mentioned. I will try a quick 1.7 demo project and see if I have issues.

Regardless. It is still early days, so a rename of a package is still viable.

aSemy commented 2 years ago

yes I think it's a problem with kapt - I saw similar issues on the Jetbrains tracker https://youtrack.jetbrains.com/issue/KT-16153

lgwillmore commented 2 years ago

Okay - going to try and publish version 0.2.0 with a few breaking changes including this one today. Saving 1.0.0 for when we have a good solid first realease. Then we can go full semantic

lgwillmore commented 2 years ago

@aSemy 0.2.0 published. Let me know if you get same issue. Breaking change though, so you will have to update your imports

aSemy commented 2 years ago

Updating to 0.2.0 works!

I recreated it and created an issue for Kapt https://youtrack.jetbrains.com/issue/KT-53200 (with an example project attached)

Here's what kapt generates now:

import java.lang.System;

@kotlin.Metadata(mv = {1, 7, 1}, k = 2, d1 = {"\u0000\u0014\n\u0000\n\u0002\u0010 \n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0010\u0002\n\u0000\u001a\u0006\u0010\u0005\u001a\u00020\u0006\"\u0017\u0010\u0000\u001a\b\u0012\u0004\u0012\u00020\u00020\u0001\u00a2\u0006\b\n\u0000\u001a\u0004\b\u0003\u0010\u0004\u00a8\u0006\u0007"}, d2 = {"policies", "", "Lcodes/laurence/warden/policy/bool/AllOf;", "getPolicies", "()Ljava/util/List;", "main", "", "bug-kapt-boolean-package"})
public final class MainKt {
    @org.jetbrains.annotations.NotNull()
    private static final java.util.List<codes.laurence.warden.policy.bool.AllOf> policies = null;

    @org.jetbrains.annotations.NotNull()
    public static final java.util.List<codes.laurence.warden.policy.bool.AllOf> getPolicies() {
        return null;
    }

    public static final void main() {
    }
}