Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

[BUG] @print shortcomings #840

Closed
Closed

Description

Title: Single-expression functions print with extra semicolon.

Description:

This makes the printed code invalid Cpp2:

example.cpp2(4,51): error: a single-expression function should end with a single semicolon (at ';')

Minimal reproducer (https://cpp2.godbolt.org/z/jGb31dK74):

#include <functional>
t: @struct @print type = {
  x: std::function<void()> = :() = _ = 0;
  y: std::function<void()> = :() 0;
}
main: () = { }
Commands:
cppfront main.cpp2
clang++18 -std=c++23 -stdlib=libc++ -lc++abi -pedantic-errors -Wall -Wextra -Wconversion -Werror=unused-result -I . main.cpp

Expected result: Printed Cpp2 code to be valid.

Actual result and error: public x: std::function<void()> = :() = _ = 0;;.

Cpp2 lowered to Cpp1:
//=== Cpp2 type declarations ====================================================


#include "cpp2util.h"


class t;
  

//=== Cpp2 type definitions and function declarations ===========================

#include <functional>
class t {
  public: std::function<void()> x {[]() -> void { static_cast<void>(0);  }}; 
  public: std::function<void()> y {[]() -> auto { return 0;  }}; 
};
auto main() -> int;

//=== Cpp2 function definitions =================================================


auto main() -> int{}
Output:
main.cpp2...

t: type = 
{
    public x: std::function<void()> = :() = _ = 0;;

    public y: std::function<void()> = :() -> move _ = 0;;
}
 ok (mixed Cpp1/Cpp2, Cpp2 code passes safety checks)

See also:

Activity

  1. ghost added
    bug
    on Nov 17, 2023
  2. ghost changed the title [-][BUG] Single-expression functions print with extra semicolon[/-] [+][BUG] `@print` shortcomings[/+] on Nov 18, 2023
  3. AbhinavK00 commented on Nov 18, 2023

    @AbhinavK00

    Very sorry for the questions but what does print metafunction do? Also, is it confirmed that multiple metafunctions can be applied on the same type?

  4. AbhinavK00 commented on Nov 18, 2023

    @AbhinavK00

    Thanks for the answer!

  5. hsutter commented on Dec 26, 2023

    @hsutter
    Owner

    Thanks!

    I think I got them all, including the ones in your test cases and a few more... but please check and reopen with a new test case if I missed some.

  6. hsutter commented on Dec 29, 2023

    @hsutter
    Owner

    @struct doesn't generate Cpp2 code,
    but instead affects lowering.
    So it should be @printed.

    Good point, that's the simplest fix for now so I'll implement it that way. Thanks!

  7. added a commit that references this issue on Feb 1, 2024
    06f3173
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions