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

[BUG] Type generation fails on functions with an enum return value that is accessed through an entity #93

Closed
1 task done
rgrenz opened this issue Oct 12, 2023 · 3 comments · Fixed by #156
Closed
1 task done
Assignees
Labels
bug Something isn't working keepalive Will not be closed by Stale bot

Comments

@rgrenz
Copy link

rgrenz commented Oct 12, 2023

Is there an existing issue for this?

  • I have searched the existing issues

Nature of Your Project

TypeScript

Current Behavior

Since v0.11.0, when adding a CDS function that returns a value of an enum type, cds-typer fails when the enum is accessed not directly but through another entity. The output then contains a TypeError: n.match is not a function in /lib/util.js:70

Expected Behavior

cds-typer should not fail on the given example.

Steps To Reproduce

# db/stuff.cds
namespace stuff;

type Language : String enum {
    DE = 'German';
    EN = 'English'
}

entity Books {
    title    : String;
    language : Language;
}


# srv/test-service.cds
using {stuff} from '../db/stuff';

service TestService {
    entity AvailableBooks as projection on stuff.Books;

    function readOneBook() returns {
        title : stuff.Books:title;
        language : stuff.Books:language; // <-- Error. Simply accessing "stuff.Language" works fine though.
    }
}

Environment

cds-typer version: v0.11.1 **(does not occur on v0.10.0)**

Other versions:
@cap-js/sqlite: 1.3.1
@sap/cds: 7.3.0
@sap/cds-compiler: 4.3.0
@sap/cds-dk (global): 7.2.0
@sap/cds-fiori: 1.1.0
@sap/cds-foss: 4.0.2
@sap/cds-mtxs: 1.11.0
@sap/eslint-plugin-cds: 2.6.3
Node.js: v18.18.0

Repository Containing a Minimal Reproducible Example

https://github.com/rgrenz/cds-typer-issue

Anything else?

No response

@rgrenz rgrenz added bug Something isn't working new labels Oct 12, 2023
@daogrady daogrady added the keepalive Will not be closed by Stale bot label Oct 12, 2023
@daogrady
Copy link
Contributor

Hi Rouven,

thanks for reporting this issue -- good catch!
Glad you also found a workaround which will hopefully carry you over until the problem is resolved.

I'm afraid I will be out of office until November, so it will take a while before this will be fixed (unless of course you'd like to submit a PR, which is always welcome).

Best
Daniel

@rgrenz
Copy link
Author

rgrenz commented Oct 18, 2023

Hi Daniel,

Thanks for the quick response! While I probably won't have the time to write a fix myself, I took the liberty to raise another issue we encountered 😃 However, I hope you first enjoy your time off work.

Rouven

@daogrady
Copy link
Contributor

daogrady commented Feb 8, 2024

Hi Rouven,

sorry for the long wait. I have prepared a PR that fixes this issue. Feel free to use it on your actual model before I merge it to main.

Best,
Daniel

@daogrady daogrady self-assigned this Feb 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working keepalive Will not be closed by Stale bot
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants