`Rect::containsPoint` is not `const`, so a `const Rect` cannot be asked whether it holds a point

オープン 初心者向け
#60,349 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
1/5
見積もり時間
1時間未満
初心者へのやさしさ
82/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
cpp, react-native
領域
backend, mobile

調査の方向性

packages/react-native/ReactCommon/react/renderer/graphics/Rect.hを読み、特に70–74行目のcontainsPoint宣言を確認し、隣接するconst修飾されたアクセサーと比較してください。再現コードのprobe/const-frame.cppに失敗する呼び出しがあります。修正を確認するため、issue内のコマンドでコンパイルしてください。const Rect &に対してcontainsPointを呼び出した状態で、そのprobeがコンパイルできれば完了です。

索引モデルが issue の本文から書いたものです。

説明

Needs: Triage :mag:
Description

facebook::react::Rect::containsPoint(Point) (Rect.h L70-L74) only reads origin and size, yet it is the one reading member of Rect not marked const: getMaxX(), getMidY(), getCenter() and the others beside it are const noexcept. Code holding a const Rect &, such as a frame kept in a const record or passed as a const reference, cannot call it and has to copy the rectangle first. I met this in a C++ touch handler that asks each region's const frame whether it holds the touch's point.

Steps to reproduce
  1. Clone the reproducer and run bash ./reproduce.sh. It installs ReproducerApp's dependencies and compiles probe/const-frame.cpp, which calls containsPoint on a const Rect &, with -fsyntax-only against that react-native package's ReactCommon. It exits 1 while the call does not compile, 0 once it does.
  2. Or by hand, after yarn install in ReproducerApp: clang++ -std=c++20 -fsyntax-only -I ReproducerApp/node_modules/react-native/ReactCommon -I ReproducerApp/node_modules/react-native/ReactCommon/react/renderer/graphics/platform/cxx probe/const-frame.cpp

Expected: the probe compiles.
Seen: error: 'this' argument to member function 'containsPoint' has type 'const facebook::react::Rect', but function is not marked const.

React Native Version

0.90.0-nightly-20261127-7a2d1d257

Affected Platforms

Runtime - Android, Runtime - iOS

Output of npx @react-native-community/cli info
info Fetching system and libraries information...
System:
  OS: Windows 11 10.0.26300
  CPU: "(32) x64 AMD Ryzen 9 9950X3D 16-Core Processor          "
  Memory: 124.53 GB / 255.67 GB
Binaries:
  Node:
    version: 26.12.1
    path: C:\Program Files\nodejs\node.EXE
  Yarn:
    version: 1.22.22
    path: C:\Users\<user>\AppData\Roaming\npm\yarn.CMD
  npm:
    version: 12.2.1
    path: C:\Program Files\nodejs\npm.CMD
  Watchman: Not Found
SDKs:
  Android SDK: Not Found
  Windows SDK:
    AllowDevelopmentWithoutDevLicense: Enabled
    Versions:
      - 10.0.19041.0
      - 10.0.26100.0
IDEs:
  Android Studio: AI-262.9437.185.2621.16467767
  Visual Studio: Not Found
Languages:
  Java:
    version: 17.0.20.1
    path: C:\Program Files\Microsoft\jdk-17.0.20.101-hotspot\bin\javac.EXE
  Ruby: Not Found
npmPackages:
  "@react-native-community/cli":
    installed: 22.0.0-alpha.0
    wanted: 22.0.0-alpha.0
  react:
    installed: 19.3.0
    wanted: 19.3.0
  react-native:
    installed: 0.90.0-nightly-20261127-7a2d1d257
    wanted: 0.90.0-nightly-20261127-7a2d1d257
  react-native-windows: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: true
iOS:
  hermesEnabled: Not found
  newArchEnabled: Not found
Stacktrace or Logs
react-native 0.90.0-nightly-20261127-7a2d1d257, clang version 23.1.4 (https://github.com/llvm/llvm-project 7a941dfb2877a0b8cf30323fefa85ad019e0b0f5)
#include <react/renderer/graphics/Rect.h>

auto holds(const facebook::react::Rect &frame, facebook::react::Point point) -> bool {
  return frame.containsPoint(point);
}
probe/const-frame.cpp:4:10: error: 'this' argument to member function 'containsPoint' has type 'const facebook::react::Rect', but function is not marked const
    4 |   return frame.containsPoint(point);
      |          ^~~~~
ReproducerApp/node_modules/react-native/ReactCommon\react/renderer/graphics/Rect.h:70:8: note: 'containsPoint' declared here
   70 |   bool containsPoint(Point point) noexcept
      |        ^
1 error generated.
RESULT: containsPoint is not const, so a const Rect cannot call it; exit 1
MANDATORY Reproducer

https://github.com/YevheniiKotyrlo/rn-rect-contains-point-const

Screenshots and Videos

No response

主要言語
C++
スター
127k
フォーク
25.4k
平均マージ
2日 19時間
マージ済み PR(30日)
331

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

react/react-native のほかの issue

react/react-native の issue をすべて見る

似ている issue

C++ の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。