fail_self_with_arg.carbon 1.0 KB

123456789101112131415161718192021222324252627282930313233
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. //
  5. // RUN: %{not} %{explorer} %s 2>&1 | \
  6. // RUN: %{FileCheck} --match-full-lines --allow-unused-prefixes=false %s
  7. // RUN: %{not} %{explorer} --parser_debug --trace_file=- %s 2>&1 | \
  8. // RUN: %{FileCheck} --match-full-lines --allow-unused-prefixes %s
  9. // AUTOUPDATE: %{explorer} %s
  10. package ExplorerTest api;
  11. class Point(T:! Type) {
  12. // Error: wrote `Self(T)` instead of `Self`.
  13. // CHECK: COMPILATION ERROR: {{.*}}/explorer/testdata/generic_class/fail_self_with_arg.carbon:[[@LINE+1]]: in call `Self(T)`, expected callee to be a function, found `typeof(class Point(T = T:! Type))`
  14. fn Origin(zero: T) -> Self(T) {
  15. return {.x = zero, .y = zero};
  16. }
  17. // Error: wrote `Self(T)` instead of `Self`.
  18. fn GetX[me: Self(T)]() -> T {
  19. return me.x;
  20. }
  21. var x: T;
  22. var y: T;
  23. }
  24. fn Main() -> i32 {
  25. var p: Point(i32) = Point(i32).Origin(0);
  26. return p.GetX();
  27. }